fix broken tests for new psgi logging code
[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     if (my $log = $reference->{_log}) {
43         $log->clear_psgi if ($log->can('psgienv'));
44     }
45
46     if ( my $output =
47         $self->dump( $reference, $purity ) )
48     {
49
50         $c->res->headers->content_type('text/plain');
51         $c->res->output($output);
52
53         if ($context) {
54             # Repair context
55             $reference->{_context} = $context;
56             weaken( $reference->{_context} );
57         }
58
59         if ($body) {
60             # Repair body
61             delete $reference->{__body_type};
62             $reference->{_body} = $body;
63         }
64
65         return 1;
66     }
67
68     return 0;
69 }
70
71 1;