X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=8a0d54cf60c293365879007bcf2b015aed5bd239;hb=f56990fa9c318716c04de16af8f9dc19412fc226;hp=17b0d4a3da9c67b0439510f9fa5119859c1f9a08;hpb=48da4debcd3eada078c2dd7f377bb5fecb4d7f20;p=catagits%2FCatalyst-Runtime.git
diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm
index 17b0d4a..8a0d54c 100644
--- a/lib/Catalyst/Engine.pm
+++ b/lib/Catalyst/Engine.pm
@@ -10,17 +10,17 @@ 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;
+use Catalyst::Utils;
# For pretty dumps
$Data::Dumper::Terse = 1;
__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 +33,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 +107,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 +164,7 @@ sub execute {
$action = "-> $action" if $callsub =~ /forward$/;
}
+ $c->{depth}++;
eval {
if ( $c->debug )
{
@@ -167,19 +173,23 @@ sub execute {
push @{ $c->{stats} }, [ $action, sprintf( '%fs', $elapsed ) ];
$c->state(@state);
}
- else { $c->state( &$code( $class, $c, @{ $c->req->args } ) ? 1 : 0 ) }
+ 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 +215,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 +286,7 @@ sub finalize_error {
my ( $title, $error, $infos );
if ( $c->debug ) {
- $error = join '
', @{ $c->error };
+ $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 +362,12 @@ sub finalize_error {
margin: 4px;
-moz-border-radius: 10px;
}
+ code.error {
+ display: block;
+ margin: 1em 0;
+ overflow: auto;
+ white-space: pre;
+ }