| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package JSON::Pointer::Extend; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
904
|
use utf8; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
7
|
|
|
4
|
1
|
|
|
1
|
|
35
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
23
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
592
|
use JSON::Pointer; |
|
|
1
|
|
|
|
|
23841
|
|
|
|
1
|
|
|
|
|
45
|
|
|
8
|
1
|
|
|
1
|
|
12
|
use Carp qw(); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
741
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
|
13
|
3
|
|
|
3
|
0
|
2337
|
my ($class, %opt) = @_; |
|
14
|
3
|
|
|
|
|
7
|
my $self = {}; |
|
15
|
3
|
|
|
|
|
7
|
bless $self, $class; |
|
16
|
|
|
|
|
|
|
|
|
17
|
3
|
100
|
|
|
|
21
|
$opt{'-pointer'} && $self->pointer(delete $opt{'-pointer'}); |
|
18
|
3
|
100
|
|
|
|
14
|
$opt{'-document'} && $self->document(delete $opt{'-document'}); |
|
19
|
|
|
|
|
|
|
|
|
20
|
3
|
|
|
|
|
8
|
return $self; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub process { |
|
24
|
3
|
|
|
3
|
1
|
763
|
my ($self) = @_; |
|
25
|
3
|
|
33
|
|
|
7
|
my $pointer = $self->pointer // Carp::croak("'pointer' not defined"); |
|
26
|
|
|
|
|
|
|
|
|
27
|
3
|
|
|
|
|
14
|
for my $key (keys %$pointer) { |
|
28
|
5
|
|
|
|
|
2423
|
$self->_recursive_process($self->document, $key, $pointer->{$key}); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
3
|
|
|
|
|
3661
|
return 1; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _recursive_process { |
|
34
|
11
|
|
|
11
|
|
30
|
my ($self, $document, $pointer, $cb) = @_; |
|
35
|
|
|
|
|
|
|
|
|
36
|
11
|
100
|
|
|
|
67
|
if ($pointer =~ /(.*?)\/\*(.+)?/) { |
|
|
|
100
|
|
|
|
|
|
|
37
|
3
|
|
|
|
|
11
|
my $path = $1; |
|
38
|
3
|
|
|
|
|
6
|
my $tail = $2; |
|
39
|
3
|
|
|
|
|
15
|
my $arr_ref = JSON::Pointer->get($document, $path); |
|
40
|
3
|
50
|
|
|
|
372
|
if (ref($arr_ref) ne 'ARRAY') { |
|
41
|
0
|
|
|
|
|
0
|
Carp::croak("Path '$path' not array"); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
3
|
|
|
|
|
10
|
my @arr = @$arr_ref; |
|
45
|
3
|
100
|
|
|
|
7
|
if ($tail) { |
|
46
|
2
|
|
|
|
|
11
|
for my $el (@arr) { |
|
47
|
6
|
|
|
|
|
4017
|
$self->_recursive_process($el, $tail, $cb); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
else { |
|
51
|
1
|
|
|
|
|
6
|
my ($root_pointer, $field_name) = $pointer =~ /(.*)\/(.+)/; |
|
52
|
1
|
|
|
|
|
4
|
for my $el (@arr) { |
|
53
|
3
|
|
|
|
|
2553
|
$cb->($el, JSON::Pointer->get($document, $root_pointer), $field_name); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
elsif ($pointer eq '') { |
|
58
|
1
|
|
|
|
|
3
|
my $path = ''; |
|
59
|
1
|
|
|
|
|
6
|
my $arr_ref = JSON::Pointer->get($document, $path); |
|
60
|
1
|
50
|
|
|
|
104
|
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
|
|
|
|
|
3
|
for my $el (@arr) { |
|
66
|
3
|
|
|
|
|
2220
|
$cb->($el, $arr_ref, undef); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
else { |
|
70
|
7
|
|
|
|
|
54
|
my ($root_pointer, $field_name) = $pointer =~ /(.+)?\/(.+)/; |
|
71
|
7
|
100
|
|
|
|
24
|
$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
|
434
|
if (scalar(@_) > 1) { |
|
79
|
3
|
|
|
|
|
9
|
my $ref = ref($_[1]); |
|
80
|
3
|
50
|
66
|
|
|
21
|
if ($ref ne 'HASH' && $ref ne 'ARRAY') { |
|
81
|
0
|
|
|
|
|
0
|
Carp::croak("'document' must be a hashref or arrayref"); |
|
82
|
|
|
|
|
|
|
} |
|
83
|
3
|
|
|
|
|
11
|
$_[0]->{'document'} = $_[1]; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
8
|
|
|
|
|
20
|
return $_[0]->{'document'}; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub pointer { |
|
89
|
6
|
100
|
|
6
|
1
|
20
|
if (scalar(@_) > 1) { |
|
90
|
3
|
50
|
|
|
|
11
|
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
|
|
|
|
|
14
|
return $_[0]->{'pointer'}; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |