X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=b7f57fd47492cba06f9bc25fa42d48484d3ae8df;hb=13985c0aedd0003d3a722c6a729ef19e998f891c;hp=de287ea65602bfd53f84007f3c4e853681dd93d6;hpb=10011c19cb6f294d1d16c1a1fb484614a7c5dcba;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index de287ea..b7f57fd 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -10,7 +10,12 @@ use HTML::Entities; use HTTP::Body; use HTTP::Headers; use URI::QueryParam; -use Scalar::Util (); +use Encode (); +use utf8; + +use namespace::clean -except => 'meta'; + +has env => (is => 'rw', writer => '_set_env'); # input position and length has read_length => (is => 'rw'); @@ -18,8 +23,6 @@ has read_position => (is => 'rw'); has _prepared_write => (is => 'rw'); -no Moose; - # Amount of data to read from input on each pass our $CHUNKSIZE = 64 * 1024; @@ -46,11 +49,13 @@ sub finalize_body { my ( $self, $c ) = @_; my $body = $c->response->body; no warnings 'uninitialized'; - if ( Scalar::Util::blessed($body) && $body->can('read') or ref($body) eq 'GLOB' ) { - while ( !eof $body ) { - read $body, my ($buffer), $CHUNKSIZE; - last unless $self->write( $c, $buffer ); - } + if ( blessed($body) && $body->can('read') or ref($body) eq 'GLOB' ) { + my $got; + do { + $got = read $body, my ($buffer), $CHUNKSIZE; + $got = 0 unless $self->write( $c, $buffer ); + } while $got > 0; + close $body; } else { @@ -76,7 +81,7 @@ sub finalize_cookies { my $val = $response->cookies->{$name}; my $cookie = ( - Scalar::Util::blessed($val) + blessed($val) ? $val : CGI::Simple::Cookie->new( -name => $name, @@ -84,9 +89,15 @@ sub finalize_cookies { -expires => $val->{expires}, -domain => $val->{domain}, -path => $val->{path}, - -secure => $val->{secure} || 0 + -secure => $val->{secure} || 0, + -httponly => $val->{httponly} || 0, ) ); + if (!defined $cookie) { + $c->log->warn("undef passed in '$name' cookie value - not setting cookie") + if $c->debug; + next; + } push @cookies, $cookie->as_string; } @@ -104,11 +115,37 @@ is in debug mode, or a `please come back later` message otherwise. =cut +sub _dump_error_page_element { + my ($self, $i, $element) = @_; + my ($name, $val) = @{ $element }; + + # This is fugly, but the metaclass is _HUGE_ and demands waaay too much + # scrolling. Suggestions for more pleasant ways to do this welcome. + local $val->{'__MOP__'} = "Stringified: " + . $val->{'__MOP__'} if ref $val eq 'HASH' && exists $val->{'__MOP__'}; + + my $text = encode_entities( dump( $val )); + sprintf <<"EOF", $name, $text; +
%s+
%s-