line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Action::Serialize::JSON; |
2
|
|
|
|
|
|
|
$Catalyst::Action::Serialize::JSON::VERSION = '1.21'; |
3
|
2
|
|
|
2
|
|
421
|
use Moose; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
37
|
|
4
|
2
|
|
|
2
|
|
11280
|
use namespace::autoclean; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
16
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
extends 'Catalyst::Action'; |
7
|
2
|
|
|
2
|
|
210
|
use JSON::MaybeXS qw(JSON); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
567
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has encoder => ( |
10
|
|
|
|
|
|
|
is => 'ro', |
11
|
|
|
|
|
|
|
lazy_build => 1, |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _build_encoder { |
15
|
5
|
|
|
5
|
|
8
|
my $self = shift; |
16
|
5
|
|
|
|
|
24
|
return JSON->new->utf8->convert_blessed; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub execute { |
20
|
5
|
|
|
5
|
1
|
44
|
my $self = shift; |
21
|
5
|
|
|
|
|
13
|
my ( $controller, $c ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
5
|
50
|
|
|
|
15
|
if (my $options = $controller->{json_options_encode}) { |
24
|
0
|
|
|
|
|
0
|
foreach my $opt (keys %$options) { |
25
|
0
|
|
|
|
|
0
|
$self->encoder->$opt( $options->{$opt} ); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $stash_key = ( |
30
|
|
|
|
|
|
|
$controller->{'serialize'} ? |
31
|
|
|
|
|
|
|
$controller->{'serialize'}->{'stash_key'} : |
32
|
5
|
|
50
|
|
|
19
|
$controller->{'stash_key'} |
33
|
|
|
|
|
|
|
) || 'rest'; |
34
|
5
|
|
|
|
|
17
|
my $output = $self->serialize( $c->stash->{$stash_key} ); |
35
|
5
|
|
|
|
|
90
|
$c->response->output( $output ); |
36
|
5
|
|
|
|
|
167
|
return 1; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub serialize { |
40
|
5
|
|
|
5
|
0
|
310
|
my $self = shift; |
41
|
5
|
|
|
|
|
7
|
my $data = shift; |
42
|
5
|
|
|
|
|
145
|
$self->encoder->encode( $data ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|