Commit | Line | Data |
---|---|---|
fbcc39ad | 1 | package TestApp::View::Dump; |
2 | ||
3 | use strict; | |
ae0e35ee | 4 | use base 'Catalyst::View'; |
fbcc39ad | 5 | |
6 | use Data::Dumper (); | |
610bc6ec | 7 | use Scalar::Util qw(blessed weaken); |
fbcc39ad | 8 | |
9 | sub dump { | |
9310b818 | 10 | my ( $self, $reference, $purity ) = @_; |
fbcc39ad | 11 | |
12 | return unless $reference; | |
13 | ||
6721fe5a | 14 | $purity = defined $purity ? $purity : 1; |
9310b818 | 15 | |
fbcc39ad | 16 | my $dumper = Data::Dumper->new( [$reference] ); |
17 | $dumper->Indent(1); | |
9310b818 | 18 | $dumper->Purity($purity); |
fbcc39ad | 19 | $dumper->Useqq(0); |
20 | $dumper->Deepcopy(1); | |
a54d8c48 | 21 | $dumper->Quotekeys(1); |
fbcc39ad | 22 | $dumper->Terse(1); |
23 | ||
0a1a7923 | 24 | local $SIG{ __WARN__ } = sub { warn unless $_[ 0 ] =~ m{dummy} }; |
fbcc39ad | 25 | return $dumper->Dump; |
26 | } | |
27 | ||
28 | sub process { | |
9310b818 | 29 | my ( $self, $c, $reference, $purity ) = @_; |
fbcc39ad | 30 | |
31 | # Force processing of on-demand data | |
32 | $c->prepare_body; | |
33 | ||
fbcc39ad | 34 | # Remove body from reference if needed |
610bc6ec | 35 | $reference->{__body_type} = blessed $reference->body |
36 | if (blessed $reference->{_body}); | |
fbcc39ad | 37 | my $body = delete $reference->{_body}; |
38 | ||
610bc6ec | 39 | # Remove context from reference if needed |
40 | my $context = delete $reference->{_context}; | |
41 | ||
fbcc39ad | 42 | if ( my $output = |
9310b818 | 43 | $self->dump( $reference, $purity ) ) |
fbcc39ad | 44 | { |
45 | ||
46 | $c->res->headers->content_type('text/plain'); | |
47 | $c->res->output($output); | |
48 | ||
c3fd63d4 | 49 | if ($context) { |
50 | # Repair context | |
51 | $reference->{_context} = $context; | |
52 | weaken( $reference->{_context} ); | |
53 | } | |
54 | ||
55 | if ($body) { | |
56 | # Repair body | |
57 | delete $reference->{__body_type}; | |
58 | $reference->{_body} = $body; | |
59 | } | |
fbcc39ad | 60 | |
61 | return 1; | |
62 | } | |
63 | ||
64 | return 0; | |
65 | } | |
66 | ||
67 | 1; |