Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
more examples for Mojolicious::Routes::Match
  • Loading branch information
kraih committed May 12, 2013
1 parent 7632ce3 commit a8f7fa2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/Mojolicious/Renderer.pm
Expand Up @@ -24,10 +24,10 @@ my %TEMPLATES = map { $_ => slurp $HOME->rel_file($_) } @{$HOME->list_files};

sub new {
my $self = shift->SUPER::new(@_);
$self->add_handler(
json => sub { ${$_[2]} = Mojo::JSON->new->encode($_[3]{json}) });
$self->add_handler(data => sub { ${$_[2]} = $_[3]{data} });
return $self->add_handler(text => sub { ${$_[2]} = $_[3]{text} });
$self->add_handler(text => sub { ${$_[2]} = $_[3]{text} });
return $self->add_handler(
json => sub { ${$_[2]} = Mojo::JSON->new->encode($_[3]{json}) });
}

sub add_handler { shift->_add(handlers => @_) }
Expand Down
7 changes: 4 additions & 3 deletions lib/Mojolicious/Routes/Match.pm
Expand Up @@ -114,18 +114,19 @@ Mojolicious::Routes::Match - Routes visitor
# Routes
my $r = Mojolicious::Routes->new;
$r->get('/foo')->to('test#foo');
$r->put('/bar')->to('test#bar');
$r->get('/:controller/:action');
$r->put('/:controller/:action');
# Match
my $c = Mojolicious::Controller->new;
my $match = Mojolicious::Routes::Match->new(root => $r);
$match->match($c => {method => 'PUT', path => '/bar'});
$match->match($c => {method => 'PUT', path => '/foo/bar'});
say $match->stack->[0]{controller};
say $match->stack->[0]{action};
# Render
say $match->path_for;
say $match->path_for(action => 'baz');
=head1 DESCRIPTION
Expand Down

0 comments on commit a8f7fa2

Please sign in to comment.