X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst.pm;h=fef863b6f94bb71f8e7d94121a7a530735ade7fd;hb=cbffbe250eaffd02bf5af63b4869ae07f1057e1c;hp=6d77f40f1ea0645377c2817bae0b609f0c627fde;hpb=b677b4c22739a063c230215b59c37a8e4e3e9a0e;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 6d77f40..fef863b 100755 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -126,7 +126,7 @@ __PACKAGE__->stats_class('Catalyst::Stats'); # Remember to update this in Catalyst::Runtime as well! -our $VERSION = '5.90060'; +our $VERSION = '5.90064'; sub import { my ( $class, @arguments ) = @_; @@ -1133,7 +1133,6 @@ sub setup { $class->setup_log( delete $flags->{log} ); $class->setup_plugins( delete $flags->{plugins} ); - $class->setup_middleware(); $class->setup_data_handlers(); $class->setup_dispatcher( delete $flags->{dispatcher} ); if (my $engine = delete $flags->{engine}) { @@ -1174,6 +1173,8 @@ EOF $class->setup unless $Catalyst::__AM_RESTARTING; } + $class->setup_middleware(); + # Initialize our data structure $class->components( {} ); @@ -1251,9 +1252,10 @@ EOF } $class->setup_finalize; - # Should be the last thing we do so that user things hooking - # setup_finalize can log.. + + # Flush the log for good measure (in case something turned off 'autoflush' early) $class->log->_flush() if $class->log->can('_flush'); + return $class || 1; # Just in case someone named their Application 0... } @@ -1737,6 +1739,10 @@ sub execute { my $last = pop( @{ $c->stack } ); if ( my $error = $@ ) { + #rethow if this can be handled by middleware + if(blessed $error && ($error->can('as_psgi') || $error->can('code'))) { + $error->can('rethrow') ? $error->rethrow : croak $error; + } if ( blessed($error) and $error->isa('Catalyst::Exception::Detach') ) { $error->rethrow if $c->depth > 1; } @@ -2014,12 +2020,12 @@ sub handle_request { $c->dispatch; $status = $c->finalize; } catch { - chomp(my $error = $_); - $class->log->error(qq/Caught exception in engine "$error"/); #rethow if this can be handled by middleware - if(blessed $error && ($error->can('as_psgi') || $error->can('code'))) { - $error->can('rethrow') ? $error->rethrow : croak $error; + if(blessed $_ && ($_->can('as_psgi') || $_->can('code'))) { + $_->can('rethrow') ? $_->rethrow : croak $_; } + chomp(my $error = $_); + $class->log->error(qq/Caught exception in engine "$error"/); }; $COUNT++; @@ -3102,6 +3108,10 @@ which sounds odd but is likely how you expect it to work if you have prior experience with L or if you previously used the plugin L (which is now considered deprecated) +So basically your middleware handles an incoming request from the first +registered middleware, down and handles the response from the last middleware +up. + =cut sub registered_middlewares { @@ -3123,7 +3133,7 @@ sub registered_middlewares { sub setup_middleware { my $class = shift; my @middleware_definitions = @_ ? - @_ : reverse(@{$class->config->{'psgi_middleware'}||[]}); + reverse(@_) : reverse(@{$class->config->{'psgi_middleware'}||[]}); my @middleware = (); while(my $next = shift(@middleware_definitions)) { @@ -3578,7 +3588,7 @@ example given above, which uses L to provide either L it installed (if you want the faster XS parser, add it to you project Makefile.PL or dist.ini, cpanfile, etc.) -The C configuation is a hashref whose keys are HTTP Content-Types +The C configuration is a hashref whose keys are HTTP Content-Types (matched against the incoming request type using a regexp such as to be case insensitive) and whose values are coderefs that receive a localized version of C<$_> which is a filehandle object pointing to received body. @@ -3943,6 +3953,8 @@ t0m: Tomas Doran Ulf Edvinsson +vanstyn: Henry Van Styn + Viljo Marrandi C Will Hawes C