line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
107143
|
use 5.008001; |
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package # |
6
|
|
|
|
|
|
|
Template::Plugin::JSON; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:JWRIGHT'; |
9
|
|
|
|
|
|
|
our $ALT = 'Moo'; |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
555
|
use Types::Standard (); |
|
1
|
|
|
|
|
77252
|
|
|
1
|
|
|
|
|
39
|
|
12
|
1
|
|
|
1
|
|
11
|
use Carp (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
13
|
1
|
|
|
1
|
|
17
|
use JSON (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
539
|
use Alt::Template::Plugin::JSON::Moo; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
36
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
580
|
use Moo; |
|
1
|
|
|
|
|
11442
|
|
|
1
|
|
|
|
|
5
|
|
19
|
1
|
|
|
1
|
|
1990
|
use namespace::clean; |
|
1
|
|
|
|
|
12024
|
|
|
1
|
|
|
|
|
7
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
extends qw(Template::Plugin); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has context => ( |
24
|
|
|
|
|
|
|
isa => Types::Standard::Object, |
25
|
|
|
|
|
|
|
is => "ro", |
26
|
|
|
|
|
|
|
weak_ref => 1, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has json_converter => ( |
30
|
|
|
|
|
|
|
isa => Types::Standard::Object, |
31
|
|
|
|
|
|
|
is => "lazy", |
32
|
|
|
|
|
|
|
lazy_build => 1, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has json_args => ( |
36
|
|
|
|
|
|
|
isa => Types::Standard::HashRef, |
37
|
|
|
|
|
|
|
is => "ro", |
38
|
|
|
|
|
|
|
default => sub { {} }, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub BUILDARGS { |
42
|
3
|
|
|
3
|
0
|
75883
|
my ( $class, $c, @args ) = @_; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
3
|
50
|
66
|
|
|
20
|
if ( @args == 1 and not ref $args[0] ) { |
46
|
0
|
|
|
|
|
0
|
warn "Single argument form is deprecated, this module always uses JSON/JSON::XS now"; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
3
|
100
|
|
|
|
11
|
my $args = ref $args[0] ? $args[0] : {}; |
50
|
|
|
|
|
|
|
|
51
|
3
|
|
|
|
|
59
|
return { %$args, context => $c, json_args => $args }; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _build_json_converter { |
56
|
3
|
|
|
3
|
|
34
|
my $self = shift; |
57
|
|
|
|
|
|
|
|
58
|
3
|
|
|
|
|
42
|
my $json = JSON->new->allow_nonref(1); |
59
|
|
|
|
|
|
|
|
60
|
3
|
|
|
|
|
10
|
my $args = $self->json_args; |
61
|
|
|
|
|
|
|
|
62
|
3
|
|
|
|
|
20
|
for my $method (keys %$args) { |
63
|
1
|
50
|
|
|
|
12
|
if ( $json->can($method) ) { |
64
|
1
|
|
|
|
|
6
|
$json->$method( $args->{$method} ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
3
|
|
|
|
|
53
|
return $json; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub json { |
72
|
4
|
|
|
4
|
0
|
10
|
my ( $self, $value ) = @_; |
73
|
|
|
|
|
|
|
|
74
|
4
|
|
|
|
|
79
|
$self->json_converter->encode($value); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub json_decode { |
78
|
1
|
|
|
1
|
0
|
8587
|
my ( $self, $value ) = @_; |
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
|
|
33
|
$self->json_converter->decode($value); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub BUILD { |
84
|
3
|
|
|
3
|
0
|
220
|
my $self = shift; |
85
|
3
|
|
|
4
|
|
44
|
$self->context->define_vmethod( $_ => json => sub { $self->json(@_) } ) for qw(hash list scalar); |
|
4
|
|
|
|
|
292
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
1
|
|
|
1
|
|
740
|
no Moo; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
8
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__PACKAGE__; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |