Skip to content

Commit

Permalink
added experimental support for resetting under to Mojolicious::Lite
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 21, 2011
1 parent 00e28fa commit 19baa22
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Changes
@@ -1,12 +1,14 @@
This file documents the revision history for Perl extension Mojolicious.

1.99 2011-09-20 00:00:00
1.99 2011-09-21 00:00:00
- Deprecated direct hash access to the flash in
Mojolicious::Controller.
- Added EXPERIMENTAL build_frame and parse_frame methods to
Mojo::Transaction::WebSocket.
- Added EXPERIMENTAL profile helper.
- Added EXPERIMENTAL binary support to Mojo::Transaction::WebSocket.
- Added EXPERIMENTAL support for resetting under to
Mojolicious::Lite.
- Updated WebSocket implementation to ietf-15.
- Improved documentation.
- Fixed small redirect_to bug. (judofyr, sri)
Expand Down
24 changes: 23 additions & 1 deletion lib/Mojolicious/Lite.pm
Expand Up @@ -46,7 +46,7 @@ sub import {
*{"${caller}::helper"} = sub { $app->helper(@_) };
*{"${caller}::hook"} = sub { $app->hook(@_) };
*{"${caller}::under"} = *{"${caller}::ladder"} =
sub { $routes = $root->under(@_) };
sub { $routes = @_ ? $root->under(@_) : $root };
*{"${caller}::plugin"} = sub { $app->plugin(@_) };
*{"${caller}::post"} = sub { $routes->post(@_) };
*{"${caller}::put"} = sub { $routes->put(@_) };
Expand Down Expand Up @@ -546,6 +546,27 @@ Prefixing multiple routes is another good use for C<under>.
app->start;
You can also reset C<under> again.
use Mojolicious::Lite;
# /bar (put a message into the stash)
under '/bar' => {message => 'prefixed'};
# GET /bar/baz
get '/baz' => {inline => '<%= $message %>!'};
# GET /bar/yada
get '/yada' => {inline => 'also <%= $message %>!'};
# / (reset)
under;
# GET /baz
get '/baz' => {text => 'not prefixed!'};
app->start;
=head2 Conditions
Conditions such as C<agent> and C<host> from
Expand Down Expand Up @@ -830,6 +851,7 @@ See also the tutorial above for more argument variations.
=head2 C<under>
my $root = under;
my $route = under sub {...};
my $route = under '/:foo';
Expand Down
14 changes: 13 additions & 1 deletion t/mojolicious/lite_app.t
Expand Up @@ -10,7 +10,7 @@ BEGIN {
$ENV{MOJO_MODE} = 'development';
}

use Test::More tests => 903;
use Test::More tests => 908;

# Pollution
123 =~ m/(\d+)/;
Expand Down Expand Up @@ -756,6 +756,12 @@ post sub { shift->render(text => 'prefixed POST works!') };
# GET /prefix/works
get '/works' => sub { shift->render(text => 'prefix works!') };

# Reset
under;

# GET /reset
get '/reset' => {text => 'reset works!'};

# Oh Fry, I love you more than the moon, and the stars,
# and the POETIC IMAGE NUMBER 137 NOT FOUND
my $t = Test::Mojo->new;
Expand Down Expand Up @@ -1819,6 +1825,12 @@ $t->get_ok('/prefix/works')->status_is(200)
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_is('prefix works!');

# GET /reset
$t->get_ok('/reset')->status_is(200)->content_is('reset works!');

# GET /prefix/reset
$t->get_ok('/prefix/reset')->status_is(404);

# GET /captures/foo/bar
$t->get_ok('/captures/foo/bar')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
Expand Down

0 comments on commit 19baa22

Please sign in to comment.