X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=de506cb54af73eff4b1601153098817888eb5fa0;hp=22309080dd0066a22271ec02307a59dc491256a4;hb=f63c03e47ae0278e50d513b90ecbbdfd67d1a021;hpb=4d98d16dff4df87a96054967d73cf3c7a4801344 diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 2230908..de506cb 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -3,7 +3,7 @@ package Catalyst::Engine; use strict; use base 'Class::Accessor::Fast'; use CGI::Cookie; -use Data::Dumper; +use Data::Dump qw/dump/; use HTML::Entities; use HTTP::Body; use HTTP::Headers; @@ -30,13 +30,8 @@ See L. =head1 METHODS -=over 4 -=item $self->finalize_output - -, see finalize_body - -=item $self->finalize_body($c) +=head2 $self->finalize_body($c) Finalize body. Prints the response output. @@ -44,19 +39,22 @@ Finalize body. Prints the response output. sub finalize_body { my ( $self, $c ) = @_; - if ( ref $c->response->body && $c->response->body->can('read') ) { - while ( !$c->response->body->eof() ) { - $c->response->body->read( my $buffer, $CHUNKSIZE ); - $self->write( $c, $buffer ); + my $body = $c->response->body; + if ( ref $body && ( $body->can('read') || ref($body) eq 'GLOB' ) ) { + while ( !eof $body ) { + read $body, my ($buffer), $CHUNKSIZE; + last unless $self->write( $c, $buffer ); } - $c->response->body->close(); + close $body; } else { - $self->write( $c, $c->response->body ); + $self->write( $c, $body ); } } -=item $self->finalize_cookies($c) +=head2 $self->finalize_cookies($c) + +Create CGI::Cookies from $c->res->cookies, and set them as response headers. =cut @@ -78,31 +76,38 @@ sub finalize_cookies { push @cookies, $cookie->as_string; } - if (@cookies) { - $c->res->headers->push_header( 'Set-Cookie' => join ',', @cookies ); + for my $cookie (@cookies) { + $c->res->headers->push_header( 'Set-Cookie' => $cookie ); } } -=item $self->finalize_error($c) +=head2 $self->finalize_error($c) + +Output an apropriate error message, called if there's an error in $c +after the dispatch has finished. Will output debug messages if Catalyst +is in debug mode, or a `please come back later` message otherwise. =cut sub finalize_error { my ( $self, $c ) = @_; - $c->res->headers->content_type('text/html'); - my $name = $c->config->{name} || 'Catalyst Application'; + $c->res->content_type('text/html; charset=utf-8'); + my $name = $c->config->{name} || join(' ', split('::', ref $c)); my ( $title, $error, $infos ); if ( $c->debug ) { # For pretty dumps - local $Data::Dumper::Terse = 1; - $error = join '', - map { '' . encode_entities($_) . '' } - @{ $c->error }; + $error = join '', map { + '

' + . encode_entities($_) + . '

' + } @{ $c->error }; $error ||= 'No output'; + $error = qq{
$error
}; $title = $name = "$name on Catalyst $Catalyst::VERSION"; + $name = "

$name

"; # Don't show context in the dump delete $c->req->{_context}; @@ -114,24 +119,15 @@ sub finalize_error { # Don't show response header state in dump delete $c->res->{_finalized_headers}; - my $req = encode_entities Dumper $c->req; - my $res = encode_entities Dumper $c->res; - my $stash = encode_entities Dumper $c->stash; - my @infos; my $i = 0; for my $dump ( $c->dump_these ) { my $name = $dump->[0]; - my $value = encode_entities( Dumper $dump->[1] ); + my $value = encode_entities( dump( $dump->[1] )); push @infos, sprintf <<"EOF", $name, $value; -
- - %s - -
-
+

%s

-
%s
+
%s
EOF $i++; @@ -144,29 +140,33 @@ EOF $infos = <<"";
 (en) Please come back later
+(fr) SVP veuillez revenir plus tard
 (de) Bitte versuchen sie es spaeter nocheinmal
-(nl) Gelieve te komen later terug
+(at) Konnten's bitt'schoen spaeter nochmal reinschauen
 (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
+(dk) Venligst prov igen senere
+(pl) Prosze sprobowac pozniej
 
$name = ''; } $c->res->body( <<"" ); - + + + + $title -