From: John Napiorkowski Date: Wed, 31 Dec 2014 15:55:56 +0000 (-0600) Subject: Merge branch 'master' of https://github.com/davewood/catalyst-runtime X-Git-Tag: 45.90078~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=b9815ce64019ef9726acb5cf1646d9bf8af5997f;hp=b94f8e72c1c8e8348efc0eb96660dd977a838ea7 Merge branch 'master' of https://github.com/davewood/catalyst-runtime --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 14ca58e..6096f47 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1801,16 +1801,7 @@ sub execute { if ( my $error = $@ ) { #rethow if this can be handled by middleware - if( - !$c->config->{always_catch_http_exceptions} && - blessed $error && ( - $error->can('as_psgi') || - ( - $error->can('code') && - $error->code =~m/^[1-5][0-9][0-9]$/ - ) - ) - ) { + if ( $c->_handle_http_exception($error) ) { foreach my $err (@{$c->error}) { $c->log->error($err); } @@ -1923,7 +1914,7 @@ sub finalize { # Support skipping finalize for psgix.io style 'jailbreak'. Used to support # stuff like cometd and websockets - + if($c->request->_has_io_fh) { $c->log_response; return; @@ -1991,11 +1982,7 @@ sub finalize_error { $c->engine->finalize_error( $c, @_ ); } else { my ($error) = @{$c->error}; - if( - !$c->config->{always_catch_http_exceptions} && - blessed $error && - ($error->can('as_psgi') || $error->can('code')) - ) { + if ( $c->_handle_http_exception($error) ) { # In the case where the error 'knows what it wants', becauses its PSGI # aware, just rethow and let middleware catch it $error->can('rethrow') ? $error->rethrow : croak $error; @@ -2137,16 +2124,7 @@ sub handle_request { $status = $c->finalize; } catch { #rethow if this can be handled by middleware - if( - !$class->config->{always_catch_http_exceptions} && - blessed($_) && ( - $_->can('as_psgi') || - ( - $_->can('code') && - $_->code =~m/^[1-5][0-9][0-9]$/ - ) - ) - ) { + if ( $class->_handle_http_exception($_) ) { $_->can('rethrow') ? $_->rethrow : croak $_; } chomp(my $error = $_); @@ -3079,7 +3057,7 @@ sub setup_home { =head2 $c->setup_encoding -Sets up the input/output encoding. See L +Sets up the input/output encoding. See L =cut @@ -3312,7 +3290,7 @@ the plugin name does not begin with C. $class => @roles ) if @roles; } -} +} =head2 registered_middlewares @@ -3371,7 +3349,7 @@ sub registered_middlewares { sub setup_middleware { my $class = shift; - my @middleware_definitions = @_ ? + my @middleware_definitions = @_ ? reverse(@_) : reverse(@{$class->config->{'psgi_middleware'}||[]}); my @middleware = (); @@ -3475,6 +3453,22 @@ sub default_data_handlers { }; } +sub _handle_http_exception { + my ( $self, $error ) = @_; + if ( + !$self->config->{always_catch_http_exceptions} + && blessed $error + && ( + $error->can('as_psgi') + || ( $error->can('code') + && $error->code =~ m/^[1-5][0-9][0-9]$/ ) + ) + ) + { + return 1; + } +} + =head2 $c->stack Returns an arrayref of the internal execution stack (actions that are @@ -3544,7 +3538,7 @@ There are a number of 'base' config variables which can be set: C - As of version 5.90060 Catalyst rethrows errors conforming to the interface described by L and lets the middleware deal with it. -Set true to get the deprecated behaviour and have Catakyst catch HTTP exceptions. +Set true to get the deprecated behaviour and have Catalyst catch HTTP exceptions. =item * @@ -3603,7 +3597,7 @@ to be shown in hit debug tables in the test server. =item * C - Controls if the C or C environment -variable should be used for determining the request path. +variable should be used for determining the request path. Most web server environments pass the requested path to the application using environment variables, from which Catalyst has to reconstruct the request base (i.e. the top level path to / in the application, @@ -3642,7 +3636,7 @@ is having paths rewritten into it (e.g. as a .cgi/fcgi in a public_html director at other URIs than that which the app is 'normally' based at with C), the resolution of C<< $c->request->base >> will be incorrect. -=back +=back =item * @@ -3660,7 +3654,7 @@ When there is an error in an action chain, the default behavior is to continue processing the remaining actions and then catch the error upon chain end. This can lead to running actions when the application is in an unexpected state. If you have this issue, setting this config value to true will promptly exit a -chain when there is an error raised in any action (thus terminating the chain +chain when there is an error raised in any action (thus terminating the chain early.) use like: @@ -3706,7 +3700,7 @@ your stack, such as in a model that an Action is calling) that exception is caught by Catalyst and unless you either catch it yourself (via eval or something like L or by reviewing the L stack, it will eventually reach L and return either the debugging -error stack page, or the default error page. However, if your exception +error stack page, or the default error page. However, if your exception can be caught by L, L will instead rethrow it so that it can be handled by that middleware (which is part of the default middleware). For example this would allow @@ -3716,7 +3710,7 @@ is part of the default middleware). For example this would allow sub throws_exception :Local { my ($self, $c) = @_; - http_throw(SeeOther => { location => + http_throw(SeeOther => { location => $c->uri_for($self->action_for('redirect')) }); } @@ -4110,6 +4104,8 @@ Chisel Wright C Danijel Milicevic C +davewood: David Schmidt + David Kamholz Edkamholz@cpan.orgE David Naughton, C