X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=de7e082ba29e9c7ca98fd583fae07f3256992f6c;hb=62d9b03003fb7bc4be52d27b67cf0edcaaf18162;hp=fd510b37fec508b0a82e8c911fdcd7035b68a997;hpb=b4ca0ee8572ea5c33295686b7f786ab5ff43a2b7;p=catagits%2FCatalyst-Runtime.git
diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm
index fd510b3..de7e082 100644
--- a/lib/Catalyst/Engine.pm
+++ b/lib/Catalyst/Engine.pm
@@ -10,17 +10,14 @@ use HTML::Entities;
use HTTP::Headers;
use Time::HiRes qw/gettimeofday tv_interval/;
use Text::ASCIITable;
+use Catalyst::Exception;
use Catalyst::Request;
use Catalyst::Request::Upload;
use Catalyst::Response;
-
-require Module::Pluggable::Fast;
-
-# For pretty dumps
-$Data::Dumper::Terse = 1;
+use Catalyst::Utils;
__PACKAGE__->mk_classdata('components');
-__PACKAGE__->mk_accessors(qw/counter request response state/);
+__PACKAGE__->mk_accessors(qw/counter depth request response state/);
*comp = \&component;
*req = \&request;
@@ -33,6 +30,7 @@ __PACKAGE__->mk_accessors(qw/counter request response state/);
our $COUNT = 1;
our $START = time;
our $RECURSION = 1000;
+our $DETACH = "catalyst_detach\n";
=head1 NAME
@@ -106,6 +104,10 @@ sub component {
Returns a hashref containing coderefs and execution counts.
(Needed for deep recursion detection)
+=item $c->depth
+
+Returns the actual forward depth.
+
=item $c->error
=item $c->error($error, ...)
@@ -159,6 +161,7 @@ sub execute {
$action = "-> $action" if $callsub =~ /forward$/;
}
+ $c->{depth}++;
eval {
if ( $c->debug )
{
@@ -167,19 +170,23 @@ sub execute {
push @{ $c->{stats} }, [ $action, sprintf( '%fs', $elapsed ) ];
$c->state(@state);
}
- else { $c->state( &$code( $class, $c, @{ $c->req->args } ) ) }
+ else { $c->state( &$code( $class, $c, @{ $c->req->args } ) || 0 ) }
};
+ $c->{depth}--;
if ( my $error = $@ ) {
- unless ( ref $error ) {
- chomp $error;
- $error = qq/Caught exception "$error"/;
- }
+ if ( $error eq $DETACH ) { die $DETACH if $c->{depth} > 1 }
+ else {
+ unless ( ref $error ) {
+ chomp $error;
+ $error = qq/Caught exception "$error"/;
+ }
- $c->log->error($error);
- $c->error($error);
- $c->state(0);
+ $c->log->error($error);
+ $c->error($error);
+ $c->state(0);
+ }
}
return $c->state;
}
@@ -205,13 +212,21 @@ sub finalize {
$c->finalize_error;
}
- if ( !$c->response->body && $c->response->status !~ /^(1|3)\d\d$/ ) {
+ if ( !$c->response->body && $c->response->status == 200 ) {
$c->finalize_error;
}
if ( $c->response->body && !$c->response->content_length ) {
- use bytes; # play safe with a utf8 aware perl
- $c->response->content_length( length $c->response->body );
+ $c->response->content_length( bytes::length( $c->response->body ) );
+ }
+
+ if ( $c->response->status =~ /^(1\d\d|[23]04)$/ ) {
+ $c->response->headers->remove_header("Content-Length");
+ $c->response->body('');
+ }
+
+ if ( $c->request->method eq 'HEAD' ) {
+ $c->response->body('');
}
my $status = $c->finalize_headers;
@@ -268,7 +283,12 @@ sub finalize_error {
my ( $title, $error, $infos );
if ( $c->debug ) {
- $error = join '
', @{ $c->error };
+
+ # For pretty dumps
+ local $Data::Dumper::Terse = 1;
+ $error = join '',
+ map { '' . encode_entities($_) . '
' }
+ @{ $c->error };
$error ||= 'No output';
$title = $name = "$name on Catalyst $Catalyst::VERSION";
my $req = encode_entities Dumper $c->req;
@@ -344,6 +364,12 @@ sub finalize_error {
margin: 4px;
-moz-border-radius: 10px;
}
+ code.error {
+ display: block;
+ margin: 1em 0;
+ overflow: auto;
+ white-space: pre;
+ }