Skip to content

Commit

Permalink
removed prepare/finalize methods from Mojolicious
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 5, 2009
1 parent 943fd0c commit 550f704
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 52 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
This file documents the revision history for Perl extension Mojo.

0.991235 2009-07-05 00:00:00
- Removed prepare/finalize methods from Mojolicious.
- Fixed typos.

0.991234 2009-07-03 00:00:00
Expand Down
27 changes: 2 additions & 25 deletions lib/Mojolicious.pm
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,15 @@ sub dispatch {
elsif ($e) { $self->static->serve_404($c) }
}

# This will run for every request after dispatch
sub finalize { }

# Bite my shiny metal ass!
sub handler {
my ($self, $tx) = @_;

# Start timer
my $start = [Time::HiRes::gettimeofday()];

# Context
my $c = $self->build_ctx($tx);

# Prepare
$self->prepare($c);

# Dispatch unless we already have a response code
$self->dispatch($c) unless $c->res->code;

# Finalize
$self->finalize($c);
# Build context and dispatch
$self->dispatch($self->build_ctx($tx));

# End timer
my $elapsed = sprintf '%f',
Expand All @@ -128,9 +116,6 @@ sub handler {
return $tx;
}

# This will run for every request before dispatch
sub prepare { }

# This will run once at startup
sub startup { }

Expand Down Expand Up @@ -221,18 +206,10 @@ For example in production mode, C<production_mode> will be called.
$mojo->dispatch($c);
=head2 C<finalize>
$mojo->finalize($c);
=head2 C<handler>
$tx = $mojo->handler($tx);
=head2 C<prepare>
$mojo->prepare($c);
=head2 C<startup>
$mojo->startup($tx);
Expand Down
24 changes: 1 addition & 23 deletions t/mojolicious/app.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use strict;
use warnings;

use Test::More tests => 76;
use Test::More tests => 54;

use FindBin;
use lib "$FindBin::Bin/lib";
Expand All @@ -28,8 +28,6 @@ $client->process_local('MojoliciousTest', $tx);
is($tx->res->code, 500);
is($tx->res->headers->server, 'Mojo (Perl)');
is($tx->res->headers->header('X-Powered-By'), 'Mojo (Perl)');
is($tx->res->headers->header('X-Finalized'), 'works!');
is($tx->res->headers->header('X-Prepared'), 'works!');
like($tx->res->body, qr/Missing right curly/);

# Foo::test
Expand All @@ -39,8 +37,6 @@ is($tx->res->code, 200);
is($tx->res->headers->header('X-Bender'), 'Kiss my shiny metal ass!');
is($tx->res->headers->server, 'Mojo (Perl)');
is($tx->res->headers->header('X-Powered-By'), 'Mojo (Perl)');
is($tx->res->headers->header('X-Finalized'), 'works!');
is($tx->res->headers->header('X-Prepared'), 'works!');
like($tx->res->body, qr/\/bar\/test/);

# Foo::index
Expand All @@ -50,8 +46,6 @@ is($tx->res->code, 200);
is($tx->res->headers->content_type, 'text/html');
is($tx->res->headers->server, 'Mojo (Perl)');
is($tx->res->headers->header('X-Powered-By'), 'Mojo (Perl)');
is($tx->res->headers->header('X-Finalized'), 'works!');
is($tx->res->headers->header('X-Prepared'), 'works!');
like($tx->res->body, qr/<body>\n23Hello Mojo from the template \/foo! He/);

# Foo::Bar::index
Expand All @@ -61,8 +55,6 @@ is($tx->res->code, 200);
is($tx->res->headers->content_type, 'text/html');
is($tx->res->headers->server, 'Mojo (Perl)');
is($tx->res->headers->header('X-Powered-By'), 'Mojo (Perl)');
is($tx->res->headers->header('X-Finalized'), 'works!');
is($tx->res->headers->header('X-Prepared'), 'works!');
like($tx->res->body, qr/Hello Mojo from the other template \/foo-bar!/);

# Foo::templateless
Expand All @@ -72,8 +64,6 @@ $client->process_local('MojoliciousTest', $tx);
is($tx->res->code, 200);
is($tx->res->headers->server, 'Mojo (Perl)');
is($tx->res->headers->header('X-Powered-By'), 'Mojo (Perl)');
is($tx->res->headers->header('X-Finalized'), 'works!');
is($tx->res->headers->header('X-Prepared'), 'works!');
like($tx->res->body, qr/Hello Mojo from a templateless renderer!/);

# MojoliciousTest2::Foo::test
Expand All @@ -83,8 +73,6 @@ is($tx->res->code, 200);
is($tx->res->headers->header('X-Bender'), 'Kiss my shiny metal ass!');
is($tx->res->headers->server, 'Mojo (Perl)');
is($tx->res->headers->header('X-Powered-By'), 'Mojo (Perl)');
is($tx->res->headers->header('X-Finalized'), 'works!');
is($tx->res->headers->header('X-Prepared'), 'works!');
like($tx->res->body, qr/\/test2/);

# MojoliciousTestController::index
Expand All @@ -94,8 +82,6 @@ is($tx->res->code, 200);
is($tx->res->headers->header('X-Bender'), 'Kiss my shiny metal ass!');
is($tx->res->headers->server, 'Mojo (Perl)');
is($tx->res->headers->header('X-Powered-By'), 'Mojo (Perl)');
is($tx->res->headers->header('X-Finalized'), 'works!');
is($tx->res->headers->header('X-Prepared'), 'works!');
like($tx->res->body, qr/No class works!/);

# 404
Expand All @@ -104,8 +90,6 @@ $client->process_local('MojoliciousTest', $tx);
is($tx->res->code, 404);
is($tx->res->headers->server, 'Mojo (Perl)');
is($tx->res->headers->header('X-Powered-By'), 'Mojo (Perl)');
is($tx->res->headers->header('X-Finalized'), 'works!');
is($tx->res->headers->header('X-Prepared'), 'works!');
like($tx->res->body, qr/File Not Found/);

# Static file /hello.txt in a production mode
Expand All @@ -117,8 +101,6 @@ is($tx->res->code, 200);
is($tx->res->headers->content_type, 'text/plain');
is($tx->res->headers->server, 'Mojo (Perl)');
is($tx->res->headers->header('X-Powered-By'), 'Mojo (Perl)');
is($tx->res->headers->header('X-Finalized'), 'works!');
is($tx->res->headers->header('X-Prepared'), 'works!');
like($tx->res->content->file->slurp, qr/Hello Mojo from a static file!/);
$ENV{MOJO_MODE} = $backup;

Expand All @@ -140,8 +122,6 @@ is($tx->res->headers->content_length,
$stat->size, 'Content-Length is set correctly');
is($tx->res->headers->server, 'Mojo (Perl)');
is($tx->res->headers->header('X-Powered-By'), 'Mojo (Perl)');
is($tx->res->headers->header('X-Finalized'), 'works!');
is($tx->res->headers->header('X-Prepared'), 'works!');
like($tx->res->content->file->slurp,
qr/Hello Mojo from a development static file!/);
$ENV{MOJO_MODE} = $backup;
Expand All @@ -154,8 +134,6 @@ $client->process_local('MojoliciousTest', $tx);
is($tx->res->code, 304, 'Setting If-Modified-Since triggers 304');
is($tx->res->headers->server, 'Mojo (Perl)');
is($tx->res->headers->header('X-Powered-By'), 'Mojo (Perl)');
is($tx->res->headers->header('X-Finalized'), 'works!');
is($tx->res->headers->header('X-Prepared'), 'works!');
$ENV{MOJO_MODE} = $backup;

# Make sure we can override attributes with constructor arguments
Expand Down
4 changes: 0 additions & 4 deletions t/mojolicious/lib/MojoliciousTest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ sub development_mode {
$self->static->root($self->home->rel_dir('t/mojolicious/public_dev'));
}

sub finalize { $_[1]->res->headers->header('X-Finalized' => 'works!') }

sub prepare { $_[1]->res->headers->header('X-Prepared' => 'works!') }

sub production_mode {
my $self = shift;

Expand Down

0 comments on commit 550f704

Please sign in to comment.