fix reported install issue
John Napiorkowski [Fri, 3 Apr 2015 23:56:38 +0000 (18:56 -0500)]
Changes
lib/Catalyst/Plugin/SubRequest.pm

diff --git a/Changes b/Changes
index 8445440..617c22c 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 Revision history for Perl extension Catalyst::Plugin::SubRequest
 
+0.21  2015-04-03
+        - Make this work on more modern Catalyst versions.
+
 0.20  2012-08-07 18:03:00 BRT
         - Fix RT#78821
 
index a13f605..4b9486f 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 use Plack::Request;
 
-our $VERSION = '0.20';
+our $VERSION = '0.21';
 
 =head1 NAME
 
@@ -92,6 +92,11 @@ sub sub_request_response {
   local $env->{QUERY_STRING} = $uri->query || '';
   local $env->{PATH_INFO}    = $path;
   local $env->{REQUEST_URI}  = $env->{SCRIPT_NAME} . $path;
+
+  # Jump through a few hoops for backcompat with pre 5.9007x
+  local($env->{&Catalyst::Middleware::Stash::PSGI_KEY}) = &Catalyst::Middleware::Stash::_create_stash()
+    if $INC{'Catalyst/Middleware/Stash.pm'};
+
   $env->{REQUEST_URI} =~ s|//|/|g;
   my $class = ref($c) || $c;
 
@@ -102,18 +107,30 @@ sub sub_request_response {
 
   # need this so that
   my $writer = Catalyst::Plugin::SubRequest::Writer->new;
-  my $response_cb = sub { $writer };
+  my $response_cb = sub {
+    my $response = shift;
+    my ($status, $headers, $body) = @$response;
+    if($body) {
+      return;
+    } else {
+      return $writer;
+    }
+  };
+
   my $i_ctx = $class->prepare( env => $env, response_cb => $response_cb );
   $i_ctx->stash($stash);
   $i_ctx->dispatch;
   $i_ctx->finalize;
   $c->stats->profile( end => 'subrequest: ' . $path ) if $c->debug;
 
-  $i_ctx->response->body($writer->body);
+  if($writer->_is_closed) {
+    $i_ctx->response->body($writer->body);
+  }
 
   return $i_ctx->response;
 }
 
+
 package Catalyst::Plugin::SubRequest::Writer;
 use Moose;
 has body => (