fixed another regression
John Napiorkowski [Sat, 10 Jan 2015 23:30:29 +0000 (17:30 -0600)]
Changes
lib/Catalyst.pm
lib/Catalyst/Response.pm
lib/Catalyst/Runtime.pm
t/psgi_utils.t

diff --git a/Changes b/Changes
index f921176..a6d45f7 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+5.90082 - 2014-01-10
+  - Fixed a regression created in $response->from_psgi_response and test case
+    to prevent it happening again.
+
 5.90081 - 2014-01-10
   - created class attribute 'finalized_default_middleware' which determines
     if the default middleware has been added to the stack yet or not.  This
index e32c735..d6717cb 100644 (file)
@@ -129,7 +129,7 @@ __PACKAGE__->stats_class('Catalyst::Stats');
 __PACKAGE__->_encode_check(Encode::FB_CROAK | Encode::LEAVE_SRC);
 
 # Remember to update this in Catalyst::Runtime as well!
-our $VERSION = '5.90081';
+our $VERSION = '5.90082';
 $VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases
 
 sub import {
index 6143f25..74d59fe 100644 (file)
@@ -148,7 +148,10 @@ sub from_psgi_response {
         my ($status, $headers, $body) = @$psgi_res;
         $self->status($status);
         $self->headers(HTTP::Headers->new(@$headers));
-        $self->body(join('', @$body));
+        # Can be arrayref or filehandle...
+        if(defined $body) { # probably paranoia
+          ref $body eq 'ARRAY' ? $self->body(join('', @$body)) : $self->body($body);
+        }
     } elsif(ref $psgi_res eq 'CODE') {
         $psgi_res->(sub {
             my $response = shift;
@@ -156,7 +159,8 @@ sub from_psgi_response {
             $self->status($status);
             $self->headers(HTTP::Headers->new(@$headers));
             if(defined $maybe_body) {
-                $self->body(join('', @$maybe_body));
+                # Can be arrayref or filehandle...
+                ref $maybe_body eq 'ARRAY' ? $self->body(join('', @$maybe_body)) : $self->body($maybe_body);
             } else {
                 return $self->write_fh;
             }
index 466d54a..5b76616 100644 (file)
@@ -7,7 +7,7 @@ BEGIN { require 5.008003; }
 
 # Remember to update this in Catalyst as well!
 
-our $VERSION = '5.90081';
+our $VERSION = '5.90082';
 $VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases
 
 =head1 NAME
index 9c05559..eb69e9d 100644 (file)
@@ -43,6 +43,18 @@ my $psgi_app = sub {
       $psgi_app->($env));
   }
 
+  sub filehandle :Local {
+    my ($self, $c, $arg) = @_;
+    my $path = File::Spec->catfile('t', 'utf8.txt');
+    open(my $fh, '<', $path) || die "trouble: $!";
+    $c->res->from_psgi_response([200, ['Content-Type'=>'text/html'], $fh]);
+  }
+
+  sub direct :Local {
+    my ($self, $c, $arg) = @_;
+    $c->res->from_psgi_response([200, ['Content-Type'=>'text/html'], ["hello","world"]]);
+  }
+
   package MyApp::Controller::User;
   $INC{'MyApp/Controller/User.pm'} = __FILE__;
 
@@ -383,4 +395,16 @@ use Catalyst::Test 'MyApp';
   is_deeply $c->req->args, [111];
 }
 
+{
+  use utf8;
+  use Encode;
+  my ($res, $c) = ctx_request('/docs/filehandle');
+  is Encode::decode_utf8($res->content), "<p>This is stream_body_fh action ♥</p>\n";
+}
+
+{
+  my ($res, $c) = ctx_request('/docs/direct');
+  is $res->content, "helloworld";
+}
+
 done_testing();