Skip to content
Permalink
Browse files

renamed routes function to group

  • Loading branch information
kraih committed Sep 22, 2011
1 parent f659062 commit cb757f6f92e6b19eadfce625501b5877428198d3
Showing with 53 additions and 53 deletions.
  1. +1 −1 Changes
  2. +22 −22 lib/Mojolicious/Lite.pm
  3. +30 −30 t/mojolicious/lite_app.t
@@ -3,7 +3,7 @@ This file documents the revision history for Perl extension Mojolicious.
1.99 2011-09-22 00:00:00
- Deprecated direct hash access to the flash in
Mojolicious::Controller.
- Added EXPERIMENTAL routes function to Mojolicious::Lite.
- Added EXPERIMENTAL group function to Mojolicious::Lite.
- Added EXPERIMENTAL build_frame and parse_frame methods to
Mojo::Transaction::WebSocket.
- Added EXPERIMENTAL profile helper.
@@ -40,22 +40,22 @@ sub import {
no warnings 'redefine';
my $root = $routes;
*{"${caller}::new"} = *{"${caller}::app"} = sub {$app};
*{"${caller}::any"} = sub { $routes->any(@_) };
*{"${caller}::del"} = sub { $routes->del(@_) };
*{"${caller}::get"} = sub { $routes->get(@_) };
*{"${caller}::helper"} = sub { $app->helper(@_) };
*{"${caller}::hook"} = sub { $app->hook(@_) };
*{"${caller}::under"} = *{"${caller}::ladder"} =
sub { $routes = $root->under(@_) };
*{"${caller}::plugin"} = sub { $app->plugin(@_) };
*{"${caller}::post"} = sub { $routes->post(@_) };
*{"${caller}::put"} = sub { $routes->put(@_) };
*{"${caller}::routes"} = sub (&) {
*{"${caller}::any"} = sub { $routes->any(@_) };
*{"${caller}::del"} = sub { $routes->del(@_) };
*{"${caller}::get"} = sub { $routes->get(@_) };
*{"${caller}::group"} = sub (&) {
my $old = $root;
$_[0]->($root = $routes);
$routes = $root;
$root = $old;
};
*{"${caller}::helper"} = sub { $app->helper(@_) };
*{"${caller}::hook"} = sub { $app->hook(@_) };
*{"${caller}::under"} = *{"${caller}::ladder"} =
sub { $routes = $root->under(@_) };
*{"${caller}::plugin"} = sub { $app->plugin(@_) };
*{"${caller}::post"} = sub { $routes->post(@_) };
*{"${caller}::put"} = sub { $routes->put(@_) };
*{"${caller}::websocket"} = sub { $routes->websocket(@_) };

# We are most likely the app in a lite environment
@@ -563,8 +563,8 @@ Prefixing multiple routes is another good use for C<under>.
app->start;
Route blocks allow multiple C<under> statements to be nested and related
routes to be grouped.
You can also C<group> related routes, which allows nesting of multiple
C<under> statements.
use Mojolicious::Lite;
@@ -577,9 +577,9 @@ routes to be grouped.
};
# Admin section
routes {
group {
# Local logic shared only by routes in this block
# Local logic shared only by routes in this group
under '/admin' => sub {
my $self = shift;
return 1 if $self->req->heaers->header('X-Awesome');
@@ -853,6 +853,13 @@ See also the tutorial above for more argument variations.
Generate route matching only C<GET> requests.
See also the tutorial above for more argument variations.
=head2 C<group>
group {...};
Start a new route group.
Note that this function is EXPERIMENTAL and might change without warning!
=head2 C<helper>
helper foo => sub {...};
@@ -887,13 +894,6 @@ See also the tutorial above for more argument variations.
Generate route matching only C<PUT> requests.
See also the tutorial above for more argument variations.
=head2 C<routes>
routes {...};
Start a new route block.
Note that this function is EXPERIMENTAL and might change without warning!
=head2 C<under>
my $route = under sub {...};
@@ -771,31 +771,31 @@ under '/' => {foo => 'one'};
# GET /reset
get '/reset' => {text => 'reset works!'};

# Block
routes {
# Group
group {

# /block
under '/block' => {bar => 'two'};
# /group
under '/group' => {bar => 'two'};

# GET /block
# GET /group
get {inline => '<%= $foo %><%= $bar %>!'};

# Nested block
routes {
# Nested group
group {

# /block/nested
# /group/nested
under '/nested' => {baz => 'three'};

# GET /block/nested
# GET /group/nested
get {inline => '<%= $baz %><%= $bar %><%= $foo %>!'};

# GET /block/nested/whatever
# GET /group/nested/whatever
get '/whatever' => {inline => '<%= $foo %><%= $bar %><%= $baz %>!'};
};
};

# Authentication block
routes {
# Authentication group
group {

# Check "ok" parameter
under sub {
@@ -805,12 +805,12 @@ routes {
return;
};

# GET /authblock
get '/authblock' => {text => "You're ok."};
# GET /authgroup
get '/authgroup' => {text => "You're ok."};
};

# GET /noauthblock
get '/noauthblock' => {inline => 'Whatever <%= $foo %>.'};
# GET /noauthgroup
get '/noauthgroup' => {inline => 'Whatever <%= $foo %>.'};

# Oh Fry, I love you more than the moon, and the stars,
# and the POETIC IMAGE NUMBER 137 NOT FOUND
@@ -1887,27 +1887,27 @@ $t->get_ok('/reset')->status_is(200)->content_is('reset works!');
# GET /prefix/reset
$t->get_ok('/prefix/reset')->status_is(404);

# GET /block
$t->get_ok('/block')->status_is(200)->content_is("onetwo!\n");
# GET /group
$t->get_ok('/group')->status_is(200)->content_is("onetwo!\n");

# GET /block/nested
$t->get_ok('/block/nested')->status_is(200)->content_is("threetwoone!\n");
# GET /group/nested
$t->get_ok('/group/nested')->status_is(200)->content_is("threetwoone!\n");

# GET /block/nested/whatever
$t->get_ok('/block/nested/whatever')->status_is(200)
# GET /group/nested/whatever
$t->get_ok('/group/nested/whatever')->status_is(200)
->content_is("onetwothree!\n");

# GET /block/nested/something
$t->get_ok('/block/nested/something')->status_is(404);
# GET /group/nested/something
$t->get_ok('/group/nested/something')->status_is(404);

# GET /authblock?ok=1
$t->get_ok('/authblock?ok=1')->status_is(200)->content_is("You're ok.");
# GET /authgroup?ok=1
$t->get_ok('/authgroup?ok=1')->status_is(200)->content_is("You're ok.");

# GET /authblock
$t->get_ok('/authblock')->status_is(200)->content_is("You're not ok.");
# GET /authgroup
$t->get_ok('/authgroup')->status_is(200)->content_is("You're not ok.");

# GET /noauthblock
$t->get_ok('/noauthblock')->status_is(200)->content_is("Whatever one.\n");
# GET /noauthgroup
$t->get_ok('/noauthgroup')->status_is(200)->content_is("Whatever one.\n");

# GET /captures/foo/bar
$t->get_ok('/captures/foo/bar')->status_is(200)

0 comments on commit cb757f6

Please sign in to comment.
You can’t perform that action at this time.