From: Christian Hansen Date: Sat, 2 Apr 2005 05:59:33 +0000 (+0000) Subject: add $c->finalize_error and improve $c->finalize X-Git-Tag: 5.7099_04~1625 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=969647fdbaeeb9231c53350eb980202b379c634a add $c->finalize_error and improve $c->finalize --- diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 4b7fad7..b469d70 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -167,105 +167,19 @@ sub finalize { $c->response->status(302); } - if ( $c->res->status =~ /^(1\d\d|[23]04)$/ ) { - $c->response->headers->remove_content_headers; - return $c->finalize_headers; - } - - if ( !$c->res->output || $#{ $c->error } >= 0 ) { - $c->res->headers->content_type('text/html'); - my $name = $c->config->{name} || 'Catalyst Application'; - my ( $title, $error, $infos ); - if ( $c->debug ) { - $error = join '
', @{ $c->error }; - $error ||= 'No output'; - $title = $name = "$name on Catalyst $Catalyst::VERSION"; - my $req = encode_entities Dumper $c->req; - my $res = encode_entities Dumper $c->res; - my $stash = encode_entities Dumper $c->stash; - $infos = <<""; -
-Request
-
$req
-Response
-
$res
-Stash
-
$stash
- - } - else { - $title = $name; - $error = ''; - $infos = <<""; -
-(en) Please come back later
-(de) Bitte versuchen sie es spaeter nocheinmal
-(nl) Gelieve te komen later terug
-(no) Vennligst prov igjen senere
-(fr) Veuillez revenir plus tard
-(es) Vuelto por favor mas adelante
-(pt) Voltado por favor mais tarde
-(it) Ritornato prego più successivamente
-
+ if ( $#{ $c->error } >= 0 ) { + $c->finalize_error; + } - $name = ''; - } - $c->res->{output} = <<""; - - - $title - - - -
-
$error
-
$infos
-
$name
-
- - + if ( !$c->res->output && $c->res->status !~ /^(1\d\d|[23]04)$/ ) { + $c->finalize_error; + } + if ( $c->res->output ) { + use bytes; # play safe with a utf8 aware perl + $c->response->content_length( length $c->res->output ); } - $c->res->headers->content_length( length $c->res->output ); + my $status = $c->finalize_headers; $c->finalize_output; return $status; @@ -294,6 +208,109 @@ sub finalize_cookies { } } +=item $c->finalize_error + +Finalize error. + +=cut + +sub finalize_error { + my $c = shift; + + $c->res->headers->content_type('text/html'); + my $name = $c->config->{name} || 'Catalyst Application'; + + my ( $title, $error, $infos ); + if ( $c->debug ) { + $error = join '
', @{ $c->error }; + $error ||= 'No output'; + $title = $name = "$name on Catalyst $Catalyst::VERSION"; + my $req = encode_entities Dumper $c->req; + my $res = encode_entities Dumper $c->res; + my $stash = encode_entities Dumper $c->stash; + $infos = <<""; +
+Request
+
$req
+Response
+
$res
+Stash
+
$stash
+ + } + else { + $title = $name; + $error = ''; + $infos = <<""; +
+(en) Please come back later
+(de) Bitte versuchen sie es spaeter nocheinmal
+(nl) Gelieve te komen later terug
+(no) Vennligst prov igjen senere
+(fr) Veuillez revenir plus tard
+(es) Vuelto por favor mas adelante
+(pt) Voltado por favor mais tarde
+(it) Ritornato prego più successivamente
+
+ + $name = ''; + } + $c->res->output( <<"" ); + + + $title + + + +
+
$error
+
$infos
+
$name
+
+ + + +} + =item $c->finalize_headers Finalize headers. diff --git a/lib/Catalyst/Engine/Apache.pm b/lib/Catalyst/Engine/Apache.pm index f715456..ac7fe90 100644 --- a/lib/Catalyst/Engine/Apache.pm +++ b/lib/Catalyst/Engine/Apache.pm @@ -70,7 +70,7 @@ sub finalize_headers { sub finalize_output { my $c = shift; - $c->apache->print( $c->response->{output} ); + $c->apache->print( $c->response->output ); } =item $c->prepare_connection diff --git a/lib/Catalyst/Engine/Test.pm b/lib/Catalyst/Engine/Test.pm index fb6f26e..429bdad 100644 --- a/lib/Catalyst/Engine/Test.pm +++ b/lib/Catalyst/Engine/Test.pm @@ -69,7 +69,7 @@ sub finalize_headers { sub finalize_output { my $c = shift; - $c->http->response->content_ref( \$c->response->{output} ); + $c->http->response->content( $c->response->output ); } =item $c->prepare_connection