Moved end() from Catalyst::Plugin::Test::Plugin to TestApp::Controller::Root. Fixed...
[catagits/Catalyst-Runtime.git] / t / lib / TestApp / View / Dump.pm
index 7acfa6d..a59e417 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use base 'Catalyst::View';
 
 use Data::Dumper ();
-use Scalar::Util qw(weaken);
+use Scalar::Util qw(blessed weaken);
 
 sub dump {
     my ( $self, $reference ) = @_;
@@ -28,25 +28,32 @@ sub process {
     # Force processing of on-demand data
     $c->prepare_body;
 
-    # Remove context from reference if needed
-    my $context = delete $reference->{_context};
-
     # Remove body from reference if needed
+    $reference->{__body_type} = blessed $reference->body
+        if (blessed $reference->{_body});
     my $body = delete $reference->{_body};
 
+    # Remove context from reference if needed
+    my $context = delete $reference->{_context};
+
     if ( my $output =
-        $self->dump( $reference || $c->stash->{dump} || $c->stash ) )
+        $self->dump( $reference ) )
     {
 
         $c->res->headers->content_type('text/plain');
         $c->res->output($output);
 
-        # Repair context
-        $reference->{_context} = $context;
-        weaken( $reference->{_context} );
-
-        # Repair body
-        $reference->{_body} = $body;
+        if ($context) {
+            # Repair context
+            $reference->{_context} = $context;
+            weaken( $reference->{_context} );
+        }
+
+        if ($body) {
+            # Repair body
+            delete $reference->{__body_type};
+            $reference->{_body} = $body;
+        }
 
         return 1;
     }