Skip to content

Commit

Permalink
added another current_route example
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 12, 2012
1 parent 0508176 commit 0ba0545
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,6 +1,6 @@
This file documents the revision history for Perl extension Mojolicious.

2.60 2012-03-12 00:00:00
2.60 2012-03-13 00:00:00
- Added EXPERIMENTAL current_route helper to
Mojolicious::Plugin::DefaultHelpers.
- Made text_area helper a little smarter. (sshaw, sri)
Expand Down
19 changes: 11 additions & 8 deletions lib/Mojolicious/Guides/Routing.pod
Expand Up @@ -434,10 +434,10 @@ L<Mojolicious::Controller/"url_for"> for this.
->to(controller => 'foo', action => 'bar');

# Generate URL "/foo/abc" for route "test"
$self->url_for('test');
my $url = $self->url_for('test');

# Generate URL "/foo/sebastian" for route "test"
$self->url_for('test', name => 'sebastian');
my $url = $self->url_for('test', name => 'sebastian');

Nameless routes get an automatically generated one assigned that is simply
equal to the route itself without non-word characters.
Expand All @@ -446,21 +446,24 @@ equal to the route itself without non-word characters.
$r->route('/foo/bar')->to('test#stuff');

# Generate URL "/foo/bar"
$self->url_for('foobar');
my $url = $self->url_for('foobar');

To refer to the current route you can use the reserved name C<current> or no
name at all.

# Generate URL for current route
$self->url_for('current');
$self->url_for;
my $url = $self->url_for('current');
my $url = $self->url_for;

To check or get the actual name of the currently active route you can also
use the helper L<Mojolicious::Plugin::DefaultHelpers/"current_route">.
To check or get the name of the current route you can use the helper
L<Mojolicious::Plugin::DefaultHelpers/"current_route">.

# Get name for current route
# Name for current route
my $name = $self->current_route;

# Check route name in code shared by multiple routes
$self->stash(button => 'green') if $self->current_route('login');

=head2 HTTP methods

The method L<Mojolicious::Routes/"via"> allows only specific HTTP methods to
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojolicious/Plugin/DefaultHelpers.pm
Expand Up @@ -187,13 +187,13 @@ Append content to named buffer and retrieve it.
=head2 C<current_route>
% if (current_route 'hello') {
Hello World!
% if (current_route 'login') {
Welcome to Mojolicious!
% }
%= current_route
Check or get name of currently active route. Note that this helper is
EXPERIMENTAL and might change without warning!
Check or get name of current route. Note that this helper is EXPERIMENTAL and
might change without warning!
=head2 C<dumper>
Expand Down

0 comments on commit 0ba0545

Please sign in to comment.