File: Dump.pm

package info (click to toggle)
libcatalyst-perl 5.7006-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,128 kB
  • ctags: 798
  • sloc: perl: 9,937; makefile: 46
file content (57 lines) | stat: -rw-r--r-- 1,133 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package TestApp::View::Dump;

use strict;
use base 'Catalyst::Base';

use Data::Dumper ();
use Scalar::Util qw(weaken);

sub dump {
    my ( $self, $reference ) = @_;

    return unless $reference;

    my $dumper = Data::Dumper->new( [$reference] );
    $dumper->Indent(1);
    $dumper->Purity(1);
    $dumper->Useqq(0);
    $dumper->Deepcopy(1);
    $dumper->Quotekeys(0);
    $dumper->Terse(1);

    return $dumper->Dump;
}

sub process {
    my ( $self, $c, $reference ) = @_;

    # Force processing of on-demand data
    $c->prepare_body;

    # Remove context from reference if needed
    my $context = delete $reference->{_context};

    # Remove body from reference if needed
    my $body = delete $reference->{_body};

    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
        $reference->{_body} = $body;

        return 1;
    }

    return 0;
}

1;