Switched to Module::Install
[catagits/Catalyst-Runtime.git] / t / lib / TestApp / View / Dump.pm
index 9e0aa63..ad0f546 100644 (file)
@@ -1,16 +1,17 @@
 package TestApp::View::Dump;
 
 use strict;
-use base qw[Catalyst::Base];
+use base 'Catalyst::Base';
 
 use Data::Dumper ();
+use Scalar::Util qw(weaken);
 
 sub dump {
     my ( $self, $reference ) = @_;
 
     return unless $reference;
 
-    my $dumper = Data::Dumper->new( [ $reference ] );
+    my $dumper = Data::Dumper->new( [$reference] );
     $dumper->Indent(1);
     $dumper->Purity(1);
     $dumper->Useqq(0);
@@ -24,11 +25,30 @@ sub dump {
 sub process {
     my ( $self, $c, $reference ) = @_;
 
-    if ( my $output = $self->dump( $reference || $c->stash->{dump} || $c->stash ) ) {
+    # Force processing of on-demand data
+    $c->prepare_body;
 
-           $c->res->headers->content_type('text/plain');
-           $c->res->output($output);
-       return 1;
+    # Remove context from reference if needed
+    my $context = delete $reference->{_context};
+
+    # Remove body from reference if needed
+    my $body = delete $reference->{_body};
+
+    if ( my $output =
+        $self->dump( $reference || $c->stash->{dump} || $c->stash ) )
+    {
+
+        $c->res->headers->content_type('text/plain');
+        $c->res->output($output);
+
+        # Repair context
+        $reference->{_context} = $context;
+        weaken( $reference->{_context} );
+
+        # Repair body
+        $reference->{_body} = $body;
+
+        return 1;
     }
 
     return 0;