stop using Moo as a test package
[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(blessed weaken);
8
9 sub dump {
10     my ( $self, $reference, $purity ) = @_;
11
12     return unless $reference;
13
14     $purity = defined $purity ? $purity : 1;
15
16     my $dumper = Data::Dumper->new( [$reference] );
17     $dumper->Indent(1);
18     $dumper->Purity($purity);
19     $dumper->Useqq(0);
20     $dumper->Deepcopy(1);
21     $dumper->Quotekeys(1);
22     $dumper->Terse(1);
23
24     local $SIG{ __WARN__ } = sub { warn unless $_[ 0 ] =~ m{dummy} };
25     return $dumper->Dump;
26 }
27
28 sub process {
29     my ( $self, $c, $reference, $purity ) = @_;
30
31     # Force processing of on-demand data
32     $c->prepare_body;
33
34     # Remove body from reference if needed
35     $reference->{__body_type} = blessed $reference->body
36         if (blessed $reference->{_body});
37     my $body = delete $reference->{_body};
38
39     # Remove context from reference if needed
40     my $context = delete $reference->{_context};
41
42     my $env = delete $reference->{env};
43
44     if (my $log = $reference->{_log}) {
45         $log->clear_psgi if ($log->can('psgienv'));
46     }
47
48     if ( my $output =
49         $self->dump( $reference, $purity ) )
50     {
51
52         $c->res->headers->content_type('text/plain');
53         $c->res->output($output);
54
55         if ($context) {
56             # Repair context
57             $reference->{_context} = $context;
58             weaken( $reference->{_context} );
59         }
60
61         if ($body) {
62             # Repair body
63             delete $reference->{__body_type};
64             $reference->{_body} = $body;
65         }
66
67         if($env) { $reference->{env} = $env }
68
69         return 1;
70     }
71
72     return 0;
73 }
74
75 1;