X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=fa7ca6ae714f311e92bb1c9c6d0beeab0d2b9b50;hp=05536228522fa9039e9c6ac703f69ebdcc200c23;hb=d7d72ad91cc796713d84c256e08ef9b1a6473542;hpb=24b3262af814a1014fd1ed9ea0eb0dedb90f67b4 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 0553622..fa7ca6a 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -10,6 +10,7 @@ use Catalyst::Request; use Catalyst::Request::Upload; use Catalyst::Response; use Catalyst::Utils; +use File::stat; use NEXT; use Text::SimpleTable; use Path::Class; @@ -43,7 +44,7 @@ our $DETACH = "catalyst_detach\n"; require Module::Pluggable::Fast; # Helper script generation -our $CATALYST_SCRIPT_GEN = 24; +our $CATALYST_SCRIPT_GEN = 25; __PACKAGE__->mk_classdata($_) for qw/components arguments dispatcher engine log dispatcher_class @@ -388,7 +389,7 @@ Gets a L instance by name. sub controller { my ( $c, $name ) = @_; my $controller = $c->comp("Controller::$name"); - return $controller if $controller; + return $controller if defined $controller; return $c->comp("C::$name"); } @@ -403,7 +404,7 @@ Gets a L instance by name. sub model { my ( $c, $name ) = @_; my $model = $c->comp("Model::$name"); - return $model if $model; + return $model if defined $model; return $c->comp("M::$name"); } @@ -418,7 +419,7 @@ Gets a L instance by name. sub view { my ( $c, $name ) = @_; my $view = $c->comp("View::$name"); - return $view if $view; + return $view if defined $view; return $c->comp("V::$name"); } @@ -1015,7 +1016,19 @@ sub finalize_headers { # Content-Length if ( $c->response->body && !$c->response->content_length ) { - $c->response->content_length( bytes::length( $c->response->body ) ); + + # get the length from a filehandle + if ( ref $c->response->body && $c->response->body->can('read') ) { + if ( my $stat = stat $c->response->body ) { + $c->response->content_length( $stat->size ); + } + else { + $c->log->warn('Serving filehandle without a content-length'); + } + } + else { + $c->response->content_length( bytes::length( $c->response->body ) ); + } } # Errors