line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Sah::Filter::perl::Str::try_decode_json; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
4
|
|
|
|
|
|
|
our $DATE = '2020-02-11'; # DATE |
5
|
|
|
|
|
|
|
our $DIST = 'Data-Sah-Filter-perl-Str-try_decode_json'; # DIST |
6
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1364
|
use 5.010001; |
|
1
|
|
|
|
|
4
|
|
9
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
10
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
163
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub meta { |
13
|
|
|
|
|
|
|
+{ |
14
|
1
|
|
|
1
|
0
|
11
|
v => 1, |
15
|
|
|
|
|
|
|
summary => 'JSON-decode if we can, otherwise leave string as-is', |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub filter { |
20
|
1
|
|
|
1
|
0
|
12
|
my %args = @_; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
2
|
my $dt = $args{data_term}; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
1
|
my $res = {}; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
50
|
|
|
8
|
$res->{modules}{"JSON::PP"} //= 0; |
27
|
1
|
|
|
|
|
3
|
$res->{expr_filter} = join( |
28
|
|
|
|
|
|
|
"", |
29
|
|
|
|
|
|
|
"do { my \$decoded; eval { \$decoded = JSON::PP->new->allow_nonref->decode($dt); 1 }; \$@ ? $dt : \$decoded }", |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
3
|
$res; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
1; |
36
|
|
|
|
|
|
|
# ABSTRACT: JSON-decode if we can, otherwise leave string as-is |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
__END__ |