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