X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=8bc6c700bf0002b97dd43a88a76e5968d77e80d0;hp=038e2cd659fe3d5ed4b968cc197167cf34ccdaf9;hb=640faa87f0c572b58acd22124bfa6f6c59106873;hpb=4289f674045a0c2c40f512af3113ad2942cb21a0 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 038e2cd..8bc6c70 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -18,6 +18,19 @@ use URI; use Scalar::Util qw/weaken/; use attributes; +# For PAR +require Catalyst::Helper; +require Catalyst::PAR; +require Catalyst::Build; +require Catalyst::Test; + +require Catalyst::Engine::HTTP; +require Catalyst::Engine::CGI; + +require Catalyst::Controller; +require Catalyst::Model; +require Catalyst::View; + __PACKAGE__->mk_accessors( qw/counter request response state action stack namespace/ ); @@ -43,7 +56,7 @@ our $DETACH = "catalyst_detach\n"; require Module::Pluggable::Fast; # Helper script generation -our $CATALYST_SCRIPT_GEN = 11; +our $CATALYST_SCRIPT_GEN = 18; __PACKAGE__->mk_classdata($_) for qw/components arguments dispatcher engine log dispatcher_class @@ -54,7 +67,7 @@ __PACKAGE__->engine_class('Catalyst::Engine::CGI'); __PACKAGE__->request_class('Catalyst::Request'); __PACKAGE__->response_class('Catalyst::Response'); -our $VERSION = '5.53'; +our $VERSION = '5.57'; sub import { my ( $class, @arguments ) = @_; @@ -276,7 +289,9 @@ sub detach { my $c = shift; $c->dispatcher->detach( $c, @_ ) } =item $c->error($arrayref) -Returns an arrayref containing error messages. +Returns an arrayref containing error messages. If Catalyst encounters an +error while processing a request, it stores the error in $c->error. This +method should not be used to store non-fatal error messages. my @error = @{ $c->error }; @@ -284,7 +299,8 @@ Add a new error. $c->error('Something bad happened'); -Clear errors. +Clear errors. You probably don't want to clear the errors unless you are +implementing a custom error screen. $c->error(0); @@ -597,8 +613,11 @@ sub setup { <<"EOF") if ( $ENV{CATALYST_SCRIPT_GEN} && ( $ENV{CATALYST_SCRIPT_GEN} < $Catalyst::CATALYST_SCRIPT_GEN ) ); You are running an old script! - Please update by running: - catalyst.pl -nonew -scripts $class + Please update by running (this will overwrite existing files): + catalyst.pl -force -scripts $class + + or (this will not overwrite existing files): + catalyst.pl -scripts $class EOF if ( $class->debug ) { @@ -847,24 +866,6 @@ These methods are not meant to be used by end users. =over 4 -=item $c->benchmark( $coderef ) - -Takes a coderef with arguments and returns elapsed time as float. - - my ( $elapsed, $status ) = $c->benchmark( sub { return 1 } ); - $c->log->info( sprintf "Processing took %f seconds", $elapsed ); - -=cut - -sub benchmark { - my $c = shift; - my $code = shift; - my $time = [gettimeofday]; - my @return = &$code(@_); - my $elapsed = tv_interval $time; - return wantarray ? ( $elapsed, @return ) : $elapsed; -} - =item $c->components Returns a hash of components. @@ -944,22 +945,19 @@ sub execute { $action = "-> $action" if $callsub =~ /forward$/; } push( @{ $c->stack }, $code ); - eval { - if ( $c->debug ) + my $elapsed = 0; + my $start = 0; + $start = [gettimeofday] if $c->debug; + eval { $c->state( &$code( $class, $c, @{ $c->req->args } ) || 0 ) }; + $elapsed = tv_interval($start) if $c->debug; + + if ( $c->debug ) { + unless ( ( $code->name =~ /^_.*/ ) + && ( !$c->config->{show_internal_actions} ) ) { - my ( $elapsed, @state ) = - $c->benchmark( $code, $class, $c, @{ $c->req->args } ); - unless ( ( $code->name =~ /^_.*/ ) - && ( !$c->config->{show_internal_actions} ) ) - { - push @{ $c->{stats} }, [ $action, sprintf( '%fs', $elapsed ) ]; - } - $c->state(@state); + push @{ $c->{stats} }, [ $action, sprintf( '%fs', $elapsed ) ]; } - else { - $c->state( &$code( $class, $c, @{ $c->req->args } ) || 0 ); - } - }; + } pop( @{ $c->stack } ); if ( my $error = $@ ) { @@ -1129,8 +1127,9 @@ sub handle_request { }; if ( $class->debug ) { - my $elapsed; - ( $elapsed, $status ) = $class->benchmark($handler); + my $start = [gettimeofday]; + $status = &$handler; + my $elapsed = tv_interval $start; $elapsed = sprintf '%f', $elapsed; my $av = sprintf '%.3f', ( $elapsed == 0 ? '??' : ( 1 / $elapsed ) ); @@ -1496,8 +1495,7 @@ qq/Couldn't instantiate component "$component", "new() didn't return a object"/ return $instance; }; - eval "package $class;\n". - q!Module::Pluggable::Fast->import( + eval "package $class;\n" . q!Module::Pluggable::Fast->import( name => '_catalyst_components', search => [ "$class\::Controller", "$class\::C", @@ -1935,6 +1933,8 @@ David Kamholz David Naughton +Drew Taylor + Gary Ashton Jones Geoff Richards