line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::Meth; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
173054
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
140
|
|
4
|
5
|
|
|
5
|
|
24
|
use warnings; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
173
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.001006'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
3525
|
use JSON::MaybeXS; |
|
5
|
|
|
|
|
35118
|
|
|
5
|
|
|
|
|
247
|
|
9
|
5
|
|
|
5
|
|
84
|
use 5.008001; |
|
5
|
|
|
|
|
17
|
|
10
|
5
|
|
|
5
|
|
23
|
use Carp; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
254
|
|
11
|
5
|
|
|
5
|
|
21
|
use Scalar::Util qw/blessed/; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
644
|
|
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
|
|
542
|
use overload q{""} => sub { $data }, |
20
|
1
|
|
|
1
|
|
5
|
q{@{}} => sub { $data }, |
21
|
5
|
|
|
5
|
|
25
|
q{%{}} => sub { $data }; |
|
5
|
|
|
3
|
|
6
|
|
|
5
|
|
|
|
|
70
|
|
|
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__ |