X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst.pm;h=c409eb015e574fd20eaf206340ac067385f44e95;hb=817ed8ab62b7b59cc37e82d67aa45824211f75f6;hp=f9cae7ab2aecfab5a03b13d5403cb29212fc51c6;hpb=eb0d3cdea253b57559d190821a4f11b6265661ab;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index f9cae7a..c409eb0 100755 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -47,13 +47,13 @@ use Plack::Middleware::HTTPExceptions; use Plack::Middleware::FixMissingBodyInRedirect; use Plack::Middleware::MethodOverride; use Plack::Middleware::RemoveRedundantBody; +use Catalyst::Middleware::Stash; use Plack::Util; use Class::Load 'load_class'; BEGIN { require 5.008003; } has stack => (is => 'ro', default => sub { [] }); -has stash => (is => 'rw', default => sub { {} }); has state => (is => 'rw', default => 0); has stats => (is => 'rw'); has action => (is => 'rw'); @@ -126,7 +126,7 @@ __PACKAGE__->stats_class('Catalyst::Stats'); # Remember to update this in Catalyst::Runtime as well! -our $VERSION = '5.90064'; +our $VERSION = '5.90069_002'; sub import { my ( $class, @arguments ) = @_; @@ -496,21 +496,18 @@ Catalyst). =cut -around stash => sub { - my $orig = shift; - my $c = shift; - my $stash = $orig->($c); - if (@_) { - my $new_stash = @_ > 1 ? {@_} : $_[0]; - croak('stash takes a hash or hashref') unless ref $new_stash; - foreach my $key ( keys %$new_stash ) { - $stash->{$key} = $new_stash->{$key}; - } +sub stash { + my $c = shift; + my $stash = Catalyst::Middleware::Stash->get($c->req->env); + if(@_) { + my $new_stash = @_ > 1 ? {@_} : $_[0]; + croak('stash takes a hash or hashref') unless ref $new_stash; + foreach my $key ( keys %$new_stash ) { + $stash->{$key} = $new_stash->{$key}; } - - return $stash; -}; - + } + return $stash; +} =head2 $c->error @@ -564,6 +561,14 @@ sub clear_errors { $c->error(0); } +=head2 $c->has_errors + +Returns true if you have errors + +=cut + +sub has_errors { scalar(@{shift->error}) ? 1:0 } + sub _comp_search_prefixes { my $c = shift; return map $c->components->{ $_ }, $c->_comp_names_search_prefixes(@_); @@ -1252,11 +1257,9 @@ EOF } $class->setup_finalize; - - # Turn autoflush back off once setup is finished. - # TODO: this is being done purely for Static::Simple (legacy API), and has been suggested by - # mst to be removed and require/update Static::Simple to set this flag itself - $class->log->autoflush(0) if ($class->log->can('autoflush')); + + # 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... } @@ -1743,6 +1746,12 @@ sub execute { if ( my $error = $@ ) { #rethow if this can be handled by middleware if(blessed $error && ($error->can('as_psgi') || $error->can('code'))) { + foreach my $err (@{$c->error}) { + $c->log->error($err); + } + $c->clear_errors; + $c->log->_flush if $c->log->can('_flush'); + $error->can('rethrow') ? $error->rethrow : croak $error; } if ( blessed($error) and $error->isa('Catalyst::Exception::Detach') ) { @@ -1924,7 +1933,6 @@ sub finalize_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; - croak $error; } else { $c->engine->finalize_error( $c, @_ ) } @@ -2172,9 +2180,7 @@ Prepares connection. sub prepare_connection { my $c = shift; - # XXX - This is called on the engine (not the request) to maintain - # Engine::PSGI back compat. - $c->engine->prepare_connection($c); + $c->request->prepare_connection($c); } =head2 $c->prepare_cookies @@ -2596,18 +2602,15 @@ sub locate_components { my $class = shift; my $config = shift; - my @paths = qw( ::Controller ::C ::Model ::M ::View ::V ); + my @paths = qw( ::M ::Model ::V ::View ::C ::Controller ); my $extra = delete $config->{ search_extra } || []; - push @paths, @$extra; - - my $locator = Module::Pluggable::Object->new( - search_path => [ map { s/^(?=::)/$class/; $_; } @paths ], - %$config - ); + unshift @paths, @$extra; - # XXX think about ditching this sort entirely - my @comps = sort { length $a <=> length $b } $locator->plugins; + my @comps = map { sort { length($a) <=> length($b) } Module::Pluggable::Object->new( + search_path => [ map { s/^(?=::)/$class/; $_; } ($_) ], + %$config + )->plugins } @paths; return @comps; } @@ -2950,9 +2953,6 @@ sub setup_log { unless ( $class->log ) { $class->log( Catalyst::Log->new(keys %levels) ); } - - # Turn on autoflush by default: - $class->log->autoflush(1) if ($class->log->can('autoflush')); if ( $levels{debug} ) { Class::MOP::get_metaclass_by_name($class)->add_method('debug' => sub { 1 }); @@ -3123,6 +3123,7 @@ sub registered_middlewares { my $class = shift; if(my $middleware = $class->_psgi_middleware) { return ( + Catalyst::Middleware::Stash->new, Plack::Middleware::HTTPExceptions->new, Plack::Middleware::RemoveRedundantBody->new, Plack::Middleware::FixMissingBodyInRedirect->new, @@ -3204,7 +3205,8 @@ sub registered_data_handlers { if(my $data_handlers = $class->_data_handlers) { return %$data_handlers; } else { - die "You cannot call ->registered_data_handlers until data_handers has been setup"; + $class->setup_data_handlers; + return $class->registered_data_handlers; } } @@ -3958,6 +3960,8 @@ t0m: Tomas Doran Ulf Edvinsson +vanstyn: Henry Van Styn + Viljo Marrandi C Will Hawes C