X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2FTestApp%2FView%2FDump.pm;h=db7c2a0f659844f6400251086a62b813b3d571a0;hb=610bc6eccd3d749c9e14422575c3b8787f48fcf1;hp=9e0aa63790881c16722ff208ca2c68985657ef2c;hpb=dd4e6fd2152eea9f5b0c1f559575ced7684ef257;p=catagits%2FCatalyst-Runtime.git diff --git a/t/lib/TestApp/View/Dump.pm b/t/lib/TestApp/View/Dump.pm index 9e0aa63..db7c2a0 100644 --- a/t/lib/TestApp/View/Dump.pm +++ b/t/lib/TestApp/View/Dump.pm @@ -1,16 +1,17 @@ package TestApp::View::Dump; use strict; -use base qw[Catalyst::Base]; +use base 'Catalyst::View'; use Data::Dumper (); +use Scalar::Util qw(blessed 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,33 @@ 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 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 ) ) + { + + $c->res->headers->content_type('text/plain'); + $c->res->output($output); + + # Repair context + $reference->{_context} = $context; + weaken( $reference->{_context} ); + + # Repair body + delete $reference->{__body_type}; + $reference->{_body} = $body; + + return 1; } return 0;