line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::Pointer::Extend; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
697
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
27
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
485
|
use JSON::Pointer; |
|
1
|
|
|
|
|
18957
|
|
|
1
|
|
|
|
|
80
|
|
8
|
1
|
|
|
1
|
|
11
|
use Carp qw(); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
618
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
3
|
|
|
3
|
0
|
1873
|
my ($class, %opt) = @_; |
14
|
3
|
|
|
|
|
7
|
my $self = {}; |
15
|
3
|
|
|
|
|
5
|
bless $self, $class; |
16
|
|
|
|
|
|
|
|
17
|
3
|
100
|
|
|
|
16
|
$opt{'-pointer'} && $self->pointer(delete $opt{'-pointer'}); |
18
|
3
|
100
|
|
|
|
11
|
$opt{'-document'} && $self->document(delete $opt{'-document'}); |
19
|
|
|
|
|
|
|
|
20
|
3
|
|
|
|
|
7
|
return $self; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub process { |
24
|
3
|
|
|
3
|
1
|
627
|
my ($self) = @_; |
25
|
3
|
|
33
|
|
|
8
|
my $pointer = $self->pointer // Carp::croak("'pointer' not defined"); |
26
|
|
|
|
|
|
|
|
27
|
3
|
|
|
|
|
10
|
for my $key (keys %$pointer) { |
28
|
5
|
|
|
|
|
2178
|
$self->_recursive_process($self->document, $key, $pointer->{$key}); |
29
|
|
|
|
|
|
|
} |
30
|
3
|
|
|
|
|
2553
|
return 1; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _recursive_process { |
34
|
11
|
|
|
11
|
|
27
|
my ($self, $document, $pointer, $cb) = @_; |
35
|
|
|
|
|
|
|
|
36
|
11
|
100
|
|
|
|
56
|
if ($pointer =~ /(.*?)\/\*(.+)?/) { |
|
|
100
|
|
|
|
|
|
37
|
3
|
|
|
|
|
9
|
my $path = $1; |
38
|
3
|
|
|
|
|
17
|
my $tail = $2; |
39
|
3
|
|
|
|
|
14
|
my $arr_ref = JSON::Pointer->get($document, $path); |
40
|
3
|
50
|
|
|
|
404
|
if (ref($arr_ref) ne 'ARRAY') { |
41
|
0
|
|
|
|
|
0
|
Carp::croak("Path '$path' not array"); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
3
|
|
|
|
|
6
|
my @arr = @$arr_ref; |
45
|
3
|
100
|
|
|
|
7
|
if ($tail) { |
46
|
2
|
|
|
|
|
4
|
for my $el (@arr) { |
47
|
6
|
|
|
|
|
3107
|
$self->_recursive_process($el, $tail, $cb); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else { |
51
|
1
|
|
|
|
|
14
|
my ($root_pointer, $field_name) = $pointer =~ /(.*)\/(.+)/; |
52
|
1
|
|
|
|
|
8
|
for my $el (@arr) { |
53
|
3
|
|
|
|
|
2224
|
$cb->($el, JSON::Pointer->get($document, $root_pointer), $field_name); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif ($pointer eq '') { |
58
|
1
|
|
|
|
|
2
|
my $path = ''; |
59
|
1
|
|
|
|
|
6
|
my $arr_ref = JSON::Pointer->get($document, $path); |
60
|
1
|
50
|
|
|
|
76
|
if (ref($arr_ref) ne 'ARRAY') { |
61
|
0
|
|
|
|
|
0
|
Carp::croak("Path '$path' not array"); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
4
|
my @arr = @$arr_ref; |
65
|
1
|
|
|
|
|
2
|
for my $el (@arr) { |
66
|
3
|
|
|
|
|
1788
|
$cb->($el, $arr_ref, undef); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else { |
70
|
7
|
|
|
|
|
39
|
my ($root_pointer, $field_name) = $pointer =~ /(.+)?\/(.+)/; |
71
|
7
|
100
|
|
|
|
20
|
$cb->(JSON::Pointer->get($document, $pointer), $root_pointer ? JSON::Pointer->get($document, $root_pointer) : $document, $field_name); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
############################### GET/SET METHODS ############################## |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub document { |
78
|
8
|
100
|
|
8
|
1
|
381
|
if (scalar(@_) > 1) { |
79
|
3
|
|
|
|
|
8
|
my $ref = ref($_[1]); |
80
|
3
|
50
|
66
|
|
|
17
|
if ($ref ne 'HASH' && $ref ne 'ARRAY') { |
81
|
0
|
|
|
|
|
0
|
Carp::croak("'document' must be a hashref or arrayref"); |
82
|
|
|
|
|
|
|
} |
83
|
3
|
|
|
|
|
7
|
$_[0]->{'document'} = $_[1]; |
84
|
|
|
|
|
|
|
} |
85
|
8
|
|
|
|
|
17
|
return $_[0]->{'document'}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub pointer { |
89
|
6
|
100
|
|
6
|
1
|
17
|
if (scalar(@_) > 1) { |
90
|
3
|
50
|
|
|
|
9
|
if (ref($_[1]) ne 'HASH') { |
91
|
0
|
|
|
|
|
0
|
Carp::croak("'pointer' must be a hashref"); |
92
|
|
|
|
|
|
|
} |
93
|
3
|
|
|
|
|
7
|
$_[0]->{'pointer'} = $_[1]; |
94
|
|
|
|
|
|
|
} |
95
|
6
|
|
|
|
|
11
|
return $_[0]->{'pointer'}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |