line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::JSON::Escape; |
2
|
1
|
|
|
1
|
|
128705
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
55
|
|
3
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use base qw/Template::Plugin/; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
1273
|
|
6
|
1
|
|
|
1
|
|
754
|
use JSON (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
487
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = 0.02; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
5
|
|
|
5
|
1
|
136500
|
my ($class, $context, $args) = @_; |
12
|
5
|
|
|
|
|
36
|
my $self = bless { json => undef, args => $args }, $class; |
13
|
|
|
|
|
|
|
|
14
|
5
|
|
|
5
|
|
28
|
my $encode = sub { $self->json_encode( @_ ) }; |
|
5
|
|
|
|
|
154
|
|
15
|
5
|
|
|
|
|
128
|
$context->define_vmethod( $_ => json => $encode ) for qw/hash list scalar/; |
16
|
5
|
|
|
|
|
351
|
$context->define_filter( json => \&json_filter ); |
17
|
|
|
|
|
|
|
|
18
|
5
|
|
|
|
|
188
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub json { |
22
|
6
|
|
|
6
|
1
|
7
|
my $self = shift; |
23
|
6
|
100
|
|
|
|
43
|
return $self->{json} if $self->{json}; |
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
|
|
50
|
my $json = JSON->new->allow_nonref; |
26
|
4
|
|
|
|
|
8
|
my $args = $self->{args}; |
27
|
4
|
|
|
|
|
17
|
for ( keys %$args ) { |
28
|
1
|
50
|
|
|
|
18
|
$json->$_( $args->{ $_ } ) if $json->can( $_ ); |
29
|
|
|
|
|
|
|
} |
30
|
4
|
|
|
|
|
71
|
return $self->{json} = $json; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub json_encode { |
34
|
5
|
|
|
5
|
0
|
8
|
my ($self, $value) = @_; |
35
|
5
|
|
|
|
|
16
|
json_filter( $self->json->encode( $value ) ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub json_decode { |
39
|
1
|
|
|
1
|
1
|
44
|
my ($self, $value) = @_; |
40
|
1
|
|
|
|
|
5
|
$self->json->decode( $value ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub json_filter { |
44
|
6
|
|
|
6
|
0
|
84
|
my $value = shift; |
45
|
6
|
|
|
|
|
19
|
$value =~ s!&!\\u0026!g; |
46
|
6
|
|
|
|
|
45
|
$value =~ s!
|
47
|
6
|
|
|
|
|
12
|
$value =~ s!>!\\u003e!g; |
48
|
6
|
|
|
|
|
15
|
$value =~ s!\+!\\u002b!g; |
49
|
6
|
|
|
|
|
14
|
$value =~ s!\x{2028}!\\u2028!g; |
50
|
6
|
|
|
|
|
12
|
$value =~ s!\x{2029}!\\u2029!g; |
51
|
6
|
|
|
|
|
25
|
$value; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |