Skip to content

Commit

Permalink
reorganize sections about conditions in the routing guide
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 27, 2015
1 parent e4c8c9f commit 7b7aa1e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

6.06 2015-03-27
6.06 2015-03-28

6.05 2015-03-24
- Fixed circular require bug in Mojo::Base and Mojo::Util.
Expand Down
17 changes: 16 additions & 1 deletion lib/Mojolicious/Guides/Routing.pod
Expand Up @@ -669,6 +669,21 @@ placeholder.
$c->render(text => "/$whatever did not match.", status => 404);
});

=head2 Conditions

Conditions such as C<headers> and C<host> from
L<Mojolicious::Plugin::HeaderCondition> allow even more powerful route
constructs.

# / (Origin: http://mojolicio.us)
$r->get('/')->over(headers => {Origin => qr/mojolicio\.us/})->to('foo#bar');

# http://mojolicio.us/perldoc
$r->get('/perldoc')->over(host => 'mojolicio.us')->to('perldoc#index');

Just be aware that conditions are too complex for the routing cache, which
normally speeds up recurring requests, and can therefore reduce performance.

=head2 Hooks

Hooks operate outside the routing system and allow you to extend the framework
Expand Down Expand Up @@ -825,7 +840,7 @@ 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">.

=head2 Conditions
=head2 Adding conditions

Sometimes you might need a little more power, for example to check the
C<User-Agent> header in multiple routes. This is where conditions come into
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/HeaderCondition.pm
Expand Up @@ -24,7 +24,7 @@ sub _headers {

# All headers need to match
my $headers = $c->req->headers;
_check(scalar $headers->header($_), $patterns->{$_}) || return undef
_check($headers->header($_), $patterns->{$_}) || return undef
for keys %$patterns;
return 1;
}
Expand Down

0 comments on commit 7b7aa1e

Please sign in to comment.