Added body_ref and body_length and minor optimization, use refs where it's possible
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine.pm
index d1716ef..cbc5896 100644 (file)
@@ -179,13 +179,12 @@ sub finalize {
         $c->finalize_error;
     }
 
-    if ( !$c->response->body && $c->response->status !~ /^(1|3)\d\d$/ ) {
+    if ( !$c->response->body_length && $c->response->status !~ /^(1|3)\d\d$/ ) {
         $c->finalize_error;
     }
 
-    if ( $c->response->body && !$c->response->content_length ) {
-        use bytes;    # play safe with a utf8 aware perl
-        $c->response->content_length( length $c->response->body );
+    if ( $c->response->body_length && !$c->response->content_length ) {
+        $c->response->content_length( $c->response->body_length );
     }
 
     my $status = $c->finalize_headers;
@@ -364,7 +363,7 @@ sub handler {
             my $elapsed;
             ( $elapsed, $status ) = $class->benchmark($handler);
             $elapsed = sprintf '%f', $elapsed;
-            my $av = sprintf '%.3f', 1 / $elapsed;
+            my $av = sprintf '%.3f', ( $elapsed == 0 ? '??' : (1 / $elapsed) );
             my $t = Text::ASCIITable->new;
             $t->setCols( 'Action', 'Time' );
             $t->setColWidth( 'Action', 64, 1 );
@@ -387,7 +386,7 @@ sub handler {
     return $status;
 }
 
-=item $c->prepare($r)
+=item $c->prepare($engine)
 
 Turns the engine-specific request( Apache, CGI ... )
 into a Catalyst context .
@@ -401,6 +400,7 @@ sub prepare {
         request => Catalyst::Request->new(
             {
                 arguments  => [],
+                body       => undef,
                 cookies    => {},
                 headers    => HTTP::Headers->new,
                 parameters => {},
@@ -409,7 +409,12 @@ sub prepare {
             }
         ),
         response => Catalyst::Response->new(
-            { cookies => {}, headers => HTTP::Headers->new, status => 200 }
+            { 
+                body       => undef,
+                cookies    => {},
+                headers    => HTTP::Headers->new,
+                status     => 200
+            }
         ),
         stash => {},
         state => 0
@@ -425,10 +430,10 @@ sub prepare {
     }
 
     $c->prepare_request($engine);
-    $c->prepare_path;
+    $c->prepare_connection;
     $c->prepare_headers;
     $c->prepare_cookies;
-    $c->prepare_connection;
+    $c->prepare_path;
     $c->prepare_action;
 
     my $method   = $c->req->method   || '';
@@ -462,7 +467,7 @@ sub prepare {
         $t->setCols( 'Key', 'Value' );
         $t->setColWidth( 'Key',   37, 1 );
         $t->setColWidth( 'Value', 36, 1 );
-        for my $key ( keys %{ $c->req->params } ) {
+        for my $key ( sort keys %{ $c->req->params } ) {
             my $param = $c->req->params->{$key};
             my $value = defined($param) ? $param : '';
             $t->addRow( $key, $value );