Skip to content

Commit

Permalink
mention how to change the route pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 10, 2015
1 parent 069ac5b commit af7493f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/Mojolicious/Guides/Routing.pod
Expand Up @@ -858,6 +858,16 @@ L<Mojolicious::Routes::Route/"remove">.
Especially for rearranging routes created by plugins this can be very useful,
to find routes by their name you can use L<Mojolicious::Routes::Route/"find">.

# GET /example/test -> {controller => 'example', action => 'test'}
$r->get('/something/else')->to('something#else')->name('test');
my $test = $r->find('test');
$test->pattern->parse('/example/test');
$test->pattern->defaults({controller => 'example', action => 'test'});

Even the route pattern and destination can still be changed with
L<Mojolicious::Routes::Pattern/"parse"> and
L<Mojolicious::Routes::Pattern/"defaults">.

=head2 Adding conditions

You can also add your own conditions with the method
Expand Down
8 changes: 8 additions & 0 deletions t/mojolicious/pattern.t
Expand Up @@ -271,4 +271,12 @@ $result = $pattern->match('/i♥mojolicious');
is_deeply $result, {one => 'i', two => 'mojolicious'}, 'right structure';
is $pattern->render($result, 1), '/i♥mojolicious', 'right result';

# Pattern reuse
$pattern = Mojolicious::Routes::Pattern->new->parse('/first')->parse('/second')
->defaults({test => 'works'});
ok !$pattern->match('/first'), 'no result';
$result = $pattern->match('/second');
is_deeply $result, {test => 'works'}, 'right structure';
is $pattern->render($result, 1), '/second', 'right result';

done_testing();

0 comments on commit af7493f

Please sign in to comment.