line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Scalar::Accessors::LikeHash::JSON; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
12010
|
use 5.008; |
|
2
|
|
|
|
|
21
|
|
|
2
|
|
|
|
|
456
|
|
4
|
2
|
|
|
2
|
|
17
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
230
|
|
5
|
2
|
|
|
2
|
|
15
|
use warnings; |
|
2
|
|
|
|
|
21
|
|
|
2
|
|
|
|
|
172
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
8
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
32
|
use JSON; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
18
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
12710
|
use Role::Tiny::With; |
|
2
|
|
|
|
|
17723
|
|
|
2
|
|
|
|
|
338
|
|
13
|
|
|
|
|
|
|
with 'Scalar::Accessors::LikeHash'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my ($j); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _empty_structure |
18
|
|
|
|
|
|
|
{ |
19
|
3
|
|
|
3
|
|
22
|
q({}); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _to_hash |
23
|
|
|
|
|
|
|
{ |
24
|
25
|
|
|
25
|
|
34
|
my ($ref) = @_; |
25
|
25
|
|
66
|
|
|
309
|
($j ||= JSON::->new)->decode($$ref); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _from_hash |
29
|
|
|
|
|
|
|
{ |
30
|
7
|
|
|
7
|
|
10
|
my ($ref, $hash) = @_; |
31
|
7
|
|
33
|
|
|
89
|
$$ref = ($j ||= JSON::->new)->encode($hash); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
__END__ |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 NAME |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Scalar::Accessors::LikeHash::JSON - access a JSON scalar string in a hash-like manner |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 SYNOPSIS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $object = Scalar::Accessors::LikeHash::JSON->new; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$object->store(some_key => 42) unless $object->exists('some_key'); |
47
|
|
|
|
|
|
|
$object->fetch('some_key'); |
48
|
|
|
|
|
|
|
$object->delete('some_key'); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# The object is internally a blessed scalarref containing JSON |
51
|
|
|
|
|
|
|
print $$object; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 DESCRIPTION |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This is a concrete implementation of L<Scalar::Accessors::LikeHash>. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This module requires L<JSON> to be installed. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 BUGS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Please report any bugs to |
62
|
|
|
|
|
|
|
L<http://rt.cpan.org/Dist/Display.html?Queue=Scalar-Accessors-LikeHash>. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 SEE ALSO |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
L<Scalar::Accessors::LikeHash>, |
67
|
|
|
|
|
|
|
L<JSON>, |
68
|
|
|
|
|
|
|
L<Acme::MooseX::JSON>. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 AUTHOR |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Toby Inkster E<lt>tobyink@cpan.orgE<gt>. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Toby Inkster. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
79
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTIES |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
84
|
|
|
|
|
|
|
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
85
|
|
|
|
|
|
|
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
86
|
|
|
|
|
|
|
|