line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::Meth; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
168256
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
124
|
|
4
|
5
|
|
|
5
|
|
25
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
187
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.001007'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
3627
|
use JSON::MaybeXS; |
|
5
|
|
|
|
|
38270
|
|
|
5
|
|
|
|
|
270
|
|
9
|
5
|
|
|
5
|
|
90
|
use 5.008001; |
|
5
|
|
|
|
|
17
|
|
10
|
5
|
|
|
5
|
|
24
|
use Carp; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
302
|
|
11
|
5
|
|
|
5
|
|
24
|
use Scalar::Util qw/blessed/; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
715
|
|
12
|
|
|
|
|
|
|
require Exporter; |
13
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
14
|
|
|
|
|
|
|
our @EXPORT = qw($j); |
15
|
|
|
|
|
|
|
our @EXPORT_OK = qw($json); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $data; |
18
|
|
|
|
|
|
|
|
19
|
3
|
|
|
3
|
|
15
|
use overload q{""} => sub { $data }, |
20
|
1
|
|
|
1
|
|
6
|
q{@{}} => sub { $data }, |
21
|
5
|
|
|
5
|
|
24
|
q{%{}} => sub { $data }; |
|
5
|
|
|
3
|
|
8
|
|
|
5
|
|
|
|
|
52
|
|
|
3
|
|
|
|
|
17
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our ( $json, $j ); |
24
|
|
|
|
|
|
|
$json = $j = bless sub { |
25
|
|
|
|
|
|
|
my $in = shift; |
26
|
|
|
|
|
|
|
return undef unless defined $in; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $json_obj = JSON::MaybeXS->new( |
29
|
|
|
|
|
|
|
convert_blessed => 1, |
30
|
|
|
|
|
|
|
allow_blessed => 1, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# plain data or object at root; just encode it |
34
|
|
|
|
|
|
|
return $data = $json_obj->decode($in) |
35
|
|
|
|
|
|
|
if not ref $in |
36
|
|
|
|
|
|
|
or ( blessed $in and blessed $in ne 'JSON::Meth' ); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
return $data = $json_obj->encode($in) |
39
|
|
|
|
|
|
|
unless ref $in eq 'JSON::Meth'; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# if we got up to here, then we're dealing with a $j->$j call |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
defined $data |
44
|
|
|
|
|
|
|
or croak 'You tried to call $j->$j, but $j does not have any data ' |
45
|
|
|
|
|
|
|
. ' stored. You need at least one encode/decode call prior to ' |
46
|
|
|
|
|
|
|
. ' this, for $j->$j to work.'; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return $data = $json_obj->decode($data) |
49
|
|
|
|
|
|
|
unless ref $data; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return $data = $json_obj->encode($data); |
52
|
|
|
|
|
|
|
}, __PACKAGE__; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
q{ |
55
|
|
|
|
|
|
|
Q: How many programmers does it take to change a light bulb? |
56
|
|
|
|
|
|
|
A: None. It's a hardware problem. |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |