Updated PAR support to use "make catalyst_par", packages are no longer written by...
[catagits/Catalyst-Runtime.git] / lib / Catalyst.pm
index aca4920..dc56b88 100644 (file)
@@ -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;
@@ -18,19 +19,6 @@ use URI;
 use Scalar::Util qw/weaken/;
 use attributes;
 
-# For PAR
-require Catalyst::Helper;
-require Catalyst::PAR;
-require Catalyst::Build;
-require Catalyst::Test;
-
-require Catalyst::Engine::HTTP;
-require Catalyst::Engine::CGI;
-
-require Catalyst::Controller;
-require Catalyst::Model;
-require Catalyst::View;
-
 __PACKAGE__->mk_accessors(
     qw/counter request response state action stack namespace/
 );
@@ -56,7 +44,7 @@ our $DETACH    = "catalyst_detach\n";
 require Module::Pluggable::Fast;
 
 # Helper script generation
-our $CATALYST_SCRIPT_GEN = 18;
+our $CATALYST_SCRIPT_GEN = 24;
 
 __PACKAGE__->mk_classdata($_)
   for qw/components arguments dispatcher engine log dispatcher_class
@@ -67,7 +55,7 @@ __PACKAGE__->engine_class('Catalyst::Engine::CGI');
 __PACKAGE__->request_class('Catalyst::Request');
 __PACKAGE__->response_class('Catalyst::Response');
 
-our $VERSION = '5.57';
+our $VERSION = '5.62';
 
 sub import {
     my ( $class, @arguments ) = @_;
@@ -401,7 +389,7 @@ Gets a L<Catalyst::Controller> 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");
 }
 
@@ -416,7 +404,7 @@ Gets a L<Catalyst::Model> 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");
 }
 
@@ -431,7 +419,7 @@ Gets a L<Catalyst::View> 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");
 }
 
@@ -687,8 +675,11 @@ sub uri_for {
 
     # join args with '/', or a blank string
     my $args = ( scalar @args ? '/' . join( '/', @args ) : '' );
-    return URI->new_abs( URI->new_abs( "$path$args", "$basepath$namespace" ),
-        $base )->canonical;
+    $args =~ s/^\/// unless $path;
+    my $res =
+      URI->new_abs( URI->new_abs( "$path$args", "$basepath$namespace" ), $base )
+      ->canonical;
+    $res;
 }
 
 =head2 $c->welcome_message
@@ -1025,7 +1016,20 @@ 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
@@ -1855,6 +1859,8 @@ Wiki:
 
 =head1 SEE ALSO
 
+=head2 L<Task::Catalyst> - All you need to start with Catalyst
+
 =head2 L<Catalyst::Manual> - The Catalyst Manual
 
 =head2 L<Catalyst::Component>, L<Catalyst::Base> - Base classes for components