latest go/visit changes, pod fixes, all tests ok
[catagits/Catalyst-Runtime.git] / t / lib / TestApp / View / Dump.pm
1 package TestApp::View::Dump;
2
3 use strict;
4 use base 'Catalyst::View';
5
6 use Data::Dumper ();
7 use Scalar::Util qw(weaken);
8
9 sub dump {
10     my ( $self, $reference ) = @_;
11
12     return unless $reference;
13
14     my $dumper = Data::Dumper->new( [$reference] );
15     $dumper->Indent(1);
16     $dumper->Purity(1);
17     $dumper->Useqq(0);
18     $dumper->Deepcopy(1);
19     $dumper->Quotekeys(0);
20     $dumper->Terse(1);
21
22     return $dumper->Dump;
23 }
24
25 sub process {
26     my ( $self, $c, $reference ) = @_;
27
28     # Force processing of on-demand data
29     $c->prepare_body;
30
31     # Remove context from reference if needed
32     my $context = delete $reference->{_context};
33
34     # Remove body from reference if needed
35     my $body = delete $reference->{_body};
36
37     if ( my $output =
38         $self->dump( $reference || $c->stash->{dump} || $c->stash ) )
39     {
40
41         $c->res->headers->content_type('text/plain');
42         $c->res->output($output);
43
44         # Repair context
45         $reference->{_context} = $context;
46         weaken( $reference->{_context} );
47
48         # Repair body
49         $reference->{_body} = $body;
50
51         return 1;
52     }
53
54     return 0;
55 }
56
57 1;