X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=1fdbfebf288a180ba4ddfb254f90fad091428a5e;hb=8408d70a428be0de835bb09ade1ff86c58e1e094;hp=85d4b3996d075d23e13cb0f66cf10b977086df7a;hpb=5fa1b216a30e313bb4a23297ee1797babe58a89b;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 85d4b39..1fdbfeb 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -10,7 +10,16 @@ use HTML::Entities; use HTTP::Body; use HTTP::Headers; use URI::QueryParam; -use Scalar::Util (); +use Moose::Util::TypeConstraints; +use Plack::Loader; +use Plack::Middleware::Conditional; +use Plack::Middleware::ReverseProxy; +use Encode (); +use utf8; + +use namespace::clean -except => 'meta'; + +has env => (is => 'ro', writer => '_set_env', clearer => '_clear_env'); # input position and length has read_length => (is => 'rw'); @@ -18,7 +27,19 @@ has read_position => (is => 'rw'); has _prepared_write => (is => 'rw'); -no Moose; +has _response_cb => ( + is => 'ro', + isa => 'CodeRef', + writer => '_set_response_cb', + clearer => '_clear_response_cb', +); + +has _writer => ( + is => 'ro', + isa => duck_type([qw(write close)]), + writer => '_set_writer', + clearer => '_clear_writer', +); # Amount of data to read from input on each pass our $CHUNKSIZE = 64 * 1024; @@ -46,16 +67,24 @@ 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 { $self->write( $c, $body ); } + + $self->_writer->close; + $self->_clear_writer; + $self->_clear_env; + + return; } =head2 $self->finalize_cookies($c) @@ -76,7 +105,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,7 +113,8 @@ sub finalize_cookies { -expires => $val->{expires}, -domain => $val->{domain}, -path => $val->{path}, - -secure => $val->{secure} || 0 + -secure => $val->{secure} || 0, + -httponly => $val->{httponly} || 0, ) ); @@ -104,11 +134,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-