Skip to content

Commit

Permalink
more realistic on_process example
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 22, 2011
1 parent f17b082 commit f3d56de
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
This file documents the revision history for Perl extension Mojolicious.

2.06 2011-10-23 00:00:00
- Improved documentation.

2.05 2011-10-22 00:00:00
- Added EXPERIMENTAL max_memory_size attribute to
Mojo::Asset::Memory.
Expand Down
7 changes: 5 additions & 2 deletions lib/Mojolicious.pm
Expand Up @@ -35,7 +35,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Leaf Fluttering In Wind';
our $VERSION = '2.05';
our $VERSION = '2.06';

# "These old doomsday devices are dangerously unstable.
# I'll rest easier not knowing where they are."
Expand Down Expand Up @@ -312,9 +312,12 @@ Request processing callback, defaults to calling the C<dispatch> method.
Generally you will use a plugin or controller instead of this, consider it
the sledgehammer in your toolbox.
my $old = $app->on_process;
$app->on_process(sub {
my ($self, $c) = @_;
$self->dispatch($c);
return $c->render(text => 'Hello world!')
if $c->req->url->path->contains('/hello');
$self->$old($c);
});
=head2 C<plugins>
Expand Down
16 changes: 15 additions & 1 deletion t/mojolicious/dispatcher_lite_app.t
Expand Up @@ -7,13 +7,24 @@ BEGIN {
$ENV{MOJO_IOWATCHER} = 'Mojo::IOWatcher';
}

use Test::More tests => 9;
use Test::More tests => 12;

# "Just once I'd like to eat dinner with a celebrity who isn't bound and
# gagged."
use Mojolicious::Lite;
use Test::Mojo;

# Wrap whole application
my $old = app->on_process;
app->on_process(
sub {
my ($self, $c) = @_;
return $c->render(text => 'Wrapped!')
if $c->req->url->path->contains('/wrap');
$self->$old($c);
}
);

# Custom dispatchers /custom
app->hook(
before_dispatch => sub {
Expand Down Expand Up @@ -48,3 +59,6 @@ $t->get_ok('/custom?a=works+too')->status_is(205)->content_is('works too');

# GET /custom_too
$t->get_ok('/custom_too')->status_is(200)->content_is('this works too');

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

0 comments on commit f3d56de

Please sign in to comment.