Fixed dispatcher, so $c->req->action(undef) works again
Sebastian Riedel [Tue, 15 Nov 2005 16:54:50 +0000 (16:54 +0000)]
Changes
lib/Catalyst.pm
lib/Catalyst/Base.pm
lib/Catalyst/Dispatcher.pm
lib/Catalyst/Request.pm

diff --git a/Changes b/Changes
index 6721e00..01a2e1c 100644 (file)
--- a/Changes
+++ b/Changes
@@ -3,6 +3,8 @@ This file documents the revision history for Perl extension Catalyst.
 5.56
         - Fixed FastCGI engine to not clobber the global %ENV on each
           request. (Sam Vilain)
+        - Updated benchmarking to work with detach
+        - Fixed dispatcher, so $c->req->action(undef) works again
 
 5.55    2005-11-15 12:55:00
         - Fixed multiple cookie handling
index c661d72..6559d20 100644 (file)
@@ -54,7 +54,7 @@ __PACKAGE__->engine_class('Catalyst::Engine::CGI');
 __PACKAGE__->request_class('Catalyst::Request');
 __PACKAGE__->response_class('Catalyst::Response');
 
-our $VERSION = '5.55';
+our $VERSION = '5.56';
 
 sub import {
     my ( $class, @arguments ) = @_;
@@ -847,24 +847,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 +926,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 +1108,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 ) );
index 2a6672b..1b672f0 100644 (file)
@@ -43,7 +43,9 @@ sub _AUTO : Private {
 
 sub _ACTION : Private {
     my ( $self, $c ) = @_;
-    $c->action->execute($c);
+    if ( ref $c->action && $c->action->isa('Catalyst::Action') ) {
+        $c->action->execute($c);
+    }
     return !@{ $c->error };
 }
 
index acd1b59..2d06a5d 100644 (file)
@@ -56,7 +56,6 @@ sub detach {
 
 sub dispatch {
     my ( $self, $c ) = @_;
-
     if ( $c->action ) {
         $c->forward( join( '/', '', $c->action->namespace, '_DISPATCH' ) );
     }
index b8caa11..c0cc729 100644 (file)
@@ -6,7 +6,7 @@ use base 'Class::Accessor::Fast';
 use IO::Socket qw[AF_INET inet_aton];
 
 __PACKAGE__->mk_accessors(
-    qw/action address arguments cookies headers match method
+    qw/address arguments cookies headers match method
       protocol query_parameters secure snippets uri user/
 );
 
@@ -81,6 +81,10 @@ thus hiding the details of the particular engine implementation.
 
 Returns the requested action as a L<Catalyst::Action> object.
 
+=cut
+
+sub action { shift->{_context}->action(@_) }
+
 =item $req->address
 
 Returns the IP address of the client.