X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FResponse.pm;h=e558e4d0be81b706da08f0646880e04a9de1479e;hb=dd4530ecdc4684838d9c0e9dc00adebb6100b022;hp=e87ba61dbf8ce88392df19ab2417406b05bbcde0;hpb=e5ac67e5d706bf2e4a4c33537479f70c409a6e4e;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Response.pm b/lib/Catalyst/Response.pm index e87ba61..e558e4d 100644 --- a/lib/Catalyst/Response.pm +++ b/lib/Catalyst/Response.pm @@ -7,6 +7,7 @@ use namespace::autoclean; use Scalar::Util 'blessed'; use Catalyst::Response::Writer; use Catalyst::Utils (); +use Ref::Util qw(is_plain_arrayref is_plain_coderef); with 'MooseX::Emulate::Class::Accessor::Fast'; @@ -103,12 +104,24 @@ has _context => ( clearer => '_clear_context', ); -before [qw(status headers content_encoding content_length content_type header)] => sub { +before [qw(status headers content_encoding content_length content_type )] => sub { my $self = shift; - $self->_context->log->warn( + $self->_context->log->warn( "Useless setting a header value after finalize_headers and the response callback has been called." . - " Not what you want." ) + " Since we don't support tail headers this will not work as you might expect." ) + if ( $self->_context && $self->finalized_headers && !$self->_has_response_cb && @_ ); +}; + +# This has to be different since the first param to ->header is the header name and presumably +# you should be able to request the header even after finalization, just not try to change it. +before 'header' => sub { + my $self = shift; + my $header = shift; + + $self->_context->log->warn( + "Useless setting a header value after finalize_headers and the response callback has been called." . + " Since we don't support tail headers this will not work as you might expect." ) if ( $self->_context && $self->finalized_headers && !$self->_has_response_cb && @_ ); }; @@ -158,15 +171,15 @@ sub from_psgi_response { if(blessed($psgi_res) && $psgi_res->can('as_psgi')) { $psgi_res = $psgi_res->as_psgi; } - if(ref $psgi_res eq 'ARRAY') { + if(is_plain_arrayref($psgi_res)) { my ($status, $headers, $body) = @$psgi_res; $self->status($status); $self->headers(HTTP::Headers->new(@$headers)); # Can be arrayref or filehandle... if(defined $body) { # probably paranoia - ref $body eq 'ARRAY' ? $self->body(join('', @$body)) : $self->body($body); + is_plain_arrayref($body) ? $self->body(join('', @$body)) : $self->body($body); } - } elsif(ref $psgi_res eq 'CODE') { + } elsif(is_plain_coderef($psgi_res)) { $psgi_res->(sub { my $response = shift; my ($status, $headers, $maybe_body) = @$response; @@ -174,7 +187,7 @@ sub from_psgi_response { $self->headers(HTTP::Headers->new(@$headers)); if(defined $maybe_body) { # Can be arrayref or filehandle... - ref $maybe_body eq 'ARRAY' ? $self->body(join('', @$maybe_body)) : $self->body($maybe_body); + is_plain_arrayref($maybe_body) ? $self->body(join('', @$maybe_body)) : $self->body($maybe_body); } else { return $self->write_fh; }