X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=bf4cc0ffa11b91a4d1371dd5fd45fa2d8d5ee494;hb=3f36a3a38cef2165355b88e7c4d1204731c60544;hp=b469d70431d7d31ec81e38522de5e15b85a070c8;hpb=969647fdbaeeb9231c53350eb980202b379c634a;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index b469d70..bf4cc0f 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -9,6 +9,7 @@ use HTML::Entities; use HTTP::Headers; use Memoize; use Time::HiRes qw/gettimeofday tv_interval/; +use Text::ASCIITable; use Tree::Simple; use Tree::Simple::Visitor::FindByPath; use Catalyst::Request; @@ -127,15 +128,16 @@ sub execute { my ( $c, $class, $code ) = @_; $class = $c->comp($class) || $class; $c->state(0); + my $callsub = ( caller(1) )[3]; eval { if ( $c->debug ) { my $action = $c->actions->{reverse}->{"$code"}; $action = "/$action" unless $action =~ /\-\>/; + $action = " $action" if $callsub =~ /forward$/; my ( $elapsed, @state ) = $c->benchmark( $code, $class, $c, @{ $c->req->args } ); - push @{ $c->{stats} }, - _prettify( $action, sprintf( '%fs', $elapsed ), '' ); + push @{ $c->{stats} }, [ $action, sprintf( '%fs', $elapsed ) ]; $c->state(@state); } else { $c->state( &$code( $class, $c, @{ $c->req->args } ) ) } @@ -161,23 +163,23 @@ sub finalize { $c->finalize_cookies; - if ( my $location = $c->res->redirect ) { + if ( my $location = $c->response->redirect ) { $c->log->debug(qq/Redirecting to "$location"/) if $c->debug; $c->response->header( Location => $location ); - $c->response->status(302); + $c->response->status(302) if $c->response->status !~ /3\d\d$/; } if ( $#{ $c->error } >= 0 ) { $c->finalize_error; } - if ( !$c->res->output && $c->res->status !~ /^(1\d\d|[23]04)$/ ) { + if ( !$c->response->output && $c->response->status !~ /^(1|3)\d\d$/ ) { $c->finalize_error; } - if ( $c->res->output ) { - use bytes; # play safe with a utf8 aware perl - $c->response->content_length( length $c->res->output ); + if ( $c->response->output && !$c->response->content_length ) { + use bytes; # play safe with a utf8 aware perl + $c->response->content_length( length $c->response->output ); } my $status = $c->finalize_headers; @@ -482,7 +484,16 @@ sub handler { ( $elapsed, $status ) = $class->benchmark($handler); $elapsed = sprintf '%f', $elapsed; my $av = sprintf '%.3f', 1 / $elapsed; - $class->log->info( "Request took $elapsed" . "s ($av/s)", @stats ); + my $t = Text::ASCIITable->new; + $t->setCols( 'Action', 'Time' ); + $t->setColWidth( 'Action', 64, 1 ); + $t->setColWidth( 'Time', 9, 1 ); + + for my $stat (@stats) { + $t->addRow(@$stat); + } + $class->log->info( "Request took $elapsed" . "s ($av/s)", + $t->draw ); } else { $status = &$handler } }; @@ -543,12 +554,15 @@ sub prepare { $c->prepare_parameters; if ( $c->debug && keys %{ $c->req->params } ) { - my @params; + my $t = Text::ASCIITable->new; + $t->setCols( 'Key', 'Value' ); + $t->setColWidth( 'Key', 37, 1 ); + $t->setColWidth( 'Value', 36, 1 ); for my $key ( keys %{ $c->req->params } ) { my $value = $c->req->params->{$key} || ''; - push @params, " $key=$value"; + $t->addRow( $key, $value ); } - $c->log->debug( 'Parameters are', @params ); + $c->log->debug( 'Parameters are', $t->draw ); } $c->prepare_uploads; return $c; @@ -573,7 +587,8 @@ sub prepare_action { if ($#$result) { my $match = $result->[1]; my @snippets = @{ $result->[2] }; - $c->log->debug(qq/Requested action "$path" matched "$match"/) + $c->log->debug( + qq/Requested action is "$path" and matched "$match"/) if $c->debug; $c->log->debug( 'Snippets are "' . join( ' ', @snippets ) . '"' ) @@ -583,7 +598,7 @@ sub prepare_action { } else { $c->req->action($path); - $c->log->debug(qq/Requested action "$path"/) if $c->debug; + $c->log->debug(qq/Requested action is "$path"/) if $c->debug; } $c->req->match($path); last; @@ -842,38 +857,55 @@ sub setup_components { $self->components->{ ref $comp } = $comp; $self->setup_actions($comp); } - my @comps; - push @comps, " $_" for keys %{ $self->components }; - $self->log->debug( 'Loaded components', @comps ) - if ( @comps && $self->debug ); + my $t = Text::ASCIITable->new; + $t->setCols('Class'); + $t->setColWidth( 'Class', 75, 1 ); + $t->addRow($_) for keys %{ $self->components }; + $self->log->debug( 'Loaded components', $t->draw ) + if ( @{ $t->{tbl_rows} } && $self->debug ); my $actions = $self->actions; - my @messages = ('Loaded private actions'); - my $walker = sub { - my ( $walker, $parent, $messages, $prefix ) = @_; + my $privates = Text::ASCIITable->new; + $privates->setCols( 'Action', 'Class', 'Code' ); + $privates->setColWidth( 'Action', 28, 1 ); + $privates->setColWidth( 'Class', 28, 1 ); + $privates->setColWidth( 'Code', 14, 1 ); + my $walker = sub { + my ( $walker, $parent, $prefix ) = @_; $prefix .= $parent->getNodeValue || ''; $prefix .= '/' unless $prefix =~ /\/$/; my $uid = $parent->getUID; for my $action ( keys %{ $actions->{private}->{$uid} } ) { my ( $class, $code ) = @{ $actions->{private}->{$uid}->{$action} }; - push @$messages, _prettify( "$prefix$action", $class, $code ); + $privates->addRow( "$prefix$action", $class, $code ); } - $walker->( $walker, $_, $messages, $prefix ) - for $parent->getAllChildren; + $walker->( $walker, $_, $prefix ) for $parent->getAllChildren; }; - $walker->( $walker, $self->tree, \@messages, '' ); - $self->log->debug(@messages) if ( $#messages && $self->debug ); - @messages = ('Loaded plain actions'); + $walker->( $walker, $self->tree, '' ); + $self->log->debug( 'Loaded private actions', $privates->draw ) + if ( @{ $privates->{tbl_rows} } && $self->debug ); + my $publics = Text::ASCIITable->new; + $publics->setCols( 'Action', 'Class', 'Code' ); + $publics->setColWidth( 'Action', 28, 1 ); + $publics->setColWidth( 'Class', 28, 1 ); + $publics->setColWidth( 'Code', 14, 1 ); + for my $plain ( sort keys %{ $actions->{plain} } ) { my ( $class, $code ) = @{ $actions->{plain}->{$plain} }; - push @messages, _prettify( "/$plain", $class, $code ); - } - $self->log->debug(@messages) if ( $#messages && $self->debug ); - @messages = ('Loaded regex actions'); + $publics->addRow( "/$plain", $class, $code ); + } + $self->log->debug( 'Loaded public actions', $publics->draw ) + if ( @{ $publics->{tbl_rows} } && $self->debug ); + my $regexes = Text::ASCIITable->new; + $regexes->setCols( 'Action', 'Class', 'Code' ); + $regexes->setColWidth( 'Action', 28, 1 ); + $regexes->setColWidth( 'Class', 28, 1 ); + $regexes->setColWidth( 'Code', 14, 1 ); for my $regex ( sort keys %{ $actions->{regex} } ) { my ( $class, $code ) = @{ $actions->{regex}->{$regex} }; - push @messages, _prettify( $regex, $class, $code ); + $regexes->addRow( $regex, $class, $code ); } - $self->log->debug(@messages) if ( $#messages && $self->debug ); + $self->log->debug( 'Loaded regex actions', $regexes->draw ) + if ( @{ $regexes->{tbl_rows} } && $self->debug ); } =item $c->stash @@ -913,16 +945,6 @@ sub _class2prefix { return $prefix; } -sub _prettify { - my ( $val1, $val2, $val3 ) = @_; - formline -' @<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>>>>>>> ', - $val1, $val2, $val3; - my $formatted = $^A; - $^A = ''; - return $formatted; -} - =back =head1 AUTHOR