line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package autobox::JSON; |
2
|
|
|
|
|
|
|
$autobox::JSON::VERSION = '0.0006'; |
3
|
2
|
|
|
2
|
|
140925
|
use 5.008; |
|
2
|
|
|
|
|
245
|
|
|
2
|
|
|
|
|
84
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
74
|
|
5
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
71
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
2307
|
use parent 'autobox'; |
|
2
|
|
|
|
|
1022
|
|
|
2
|
|
|
|
|
10
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub import { |
10
|
2
|
|
|
2
|
|
27
|
my ($class) = @_; |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
|
|
23
|
$class->SUPER::import( |
13
|
|
|
|
|
|
|
HASH => 'autobox::JSON::Ref', |
14
|
|
|
|
|
|
|
ARRAY => 'autobox::JSON::Ref', |
15
|
|
|
|
|
|
|
STRING => 'autobox::JSON::String', |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
autobox::JSON - bringing JSON functions to autobox |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 VERSION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
version 0.0006 |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 SYNOPSIS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use autobox::JSON; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
say {name => 'Jim', age => 34}->encode_json; |
32
|
|
|
|
|
|
|
# {"name":"Jim","age":46} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $person = '{"name":"Jim","age":46}'->decode_json |
35
|
|
|
|
|
|
|
# {name => 'Jim', age => 34} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $serialized_person = $person->encode_json; |
38
|
|
|
|
|
|
|
# {"name":"Jim","age":46} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# works on arrays too |
41
|
|
|
|
|
|
|
[1, 2, 3, 4, 5]->encode_json; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 METHODS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 encode_json |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
This method behaves the same as L. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 encode_json_pretty |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
This method is identical to L, except that it also "prettifies" |
52
|
|
|
|
|
|
|
the output, making it easier for us mortals to read. This is useful |
53
|
|
|
|
|
|
|
especially when dumping a JSON structure to something reasonable for, say, |
54
|
|
|
|
|
|
|
debug or other purposes. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
It is functionally the same as: |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
JSON->new->utf8->canonical->pretty->encode($ref) |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 decode_json |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
This method behaves the same as L. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 DEPRECIATED METHODS |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 to_json (depreciated) |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
This method behaves the same as L. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This method is depreciated because the JSON documentation itself |
71
|
|
|
|
|
|
|
prefers encode_json. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 from_json (depreciated) |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This method behaves the same as L. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This method is depreciated as the JSON documentation itself |
78
|
|
|
|
|
|
|
prefers decode_json. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SEE ALSO |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
C C C |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 AUTHOR |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Robin Edwards, Erobin.ge@gmail.comE |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
L |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Copyright (C) 2011 by Robin Edwards |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
95
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.12.3 or, |
96
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
package autobox::JSON::String; |
101
|
|
|
|
|
|
|
$autobox::JSON::String::VERSION = '0.0006'; |
102
|
|
|
|
|
|
|
require JSON; |
103
|
3
|
|
|
3
|
|
1617
|
sub from_json { JSON::from_json(shift); } |
104
|
3
|
|
|
3
|
|
38
|
sub decode_json { JSON::decode_json(shift); } |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
package autobox::JSON::Ref; |
107
|
|
|
|
|
|
|
$autobox::JSON::Ref::VERSION = '0.0006'; |
108
|
|
|
|
|
|
|
require JSON; |
109
|
3
|
|
|
3
|
|
2141
|
sub to_json { JSON::to_json(shift); } |
110
|
3
|
|
|
3
|
|
1917
|
sub encode_json { JSON::encode_json(shift); } |
111
|
1
|
|
|
1
|
|
499
|
sub encode_json_pretty { JSON->new->utf8->canonical->pretty->encode(shift); } |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |