line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Compare::JSON::Pointer; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
48
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
49
|
|
5
|
2
|
|
|
2
|
|
8
|
use Test2::Util::HashBase qw( pointer input json ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
15
|
|
6
|
2
|
|
|
2
|
|
1176
|
use JSON::Pointer; |
|
2
|
|
|
|
|
35091
|
|
|
2
|
|
|
|
|
63
|
|
7
|
2
|
|
|
2
|
|
15
|
use Encode (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
32
|
|
8
|
2
|
|
|
2
|
|
742
|
use parent 'Test2::Compare::Base'; |
|
2
|
|
|
|
|
553
|
|
|
2
|
|
|
|
|
23
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: Representation of a hash or array reference pointed to by a JSON pointer during deep comparison. |
11
|
|
|
|
|
|
|
our $VERSION = '0.02'; # VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
1
|
1356
|
sub operator { 'JSON PTR' } |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub name |
17
|
|
|
|
|
|
|
{ |
18
|
3
|
|
|
3
|
1
|
66
|
my($self) = @_; |
19
|
3
|
|
|
|
|
8
|
my($input, $pointer) = ($self->{+INPUT}, $self->{+POINTER}); |
20
|
3
|
100
|
|
|
|
29
|
$pointer eq '' ? "$input" : "$pointer $input"; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub verify |
24
|
|
|
|
|
|
|
{ |
25
|
8
|
|
|
8
|
1
|
1921
|
my($self, %params) = @_; |
26
|
8
|
|
|
|
|
21
|
my($got, $exists) = @params{'got','exists'}; |
27
|
|
|
|
|
|
|
|
28
|
8
|
50
|
|
|
|
22
|
return 0 unless $exists; |
29
|
8
|
|
|
|
|
23
|
return 1; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _convert_got |
33
|
|
|
|
|
|
|
{ |
34
|
8
|
|
|
8
|
|
18
|
my(undef, $got) = @_; |
35
|
|
|
|
|
|
|
|
36
|
8
|
50
|
|
|
|
21
|
if(ref $got) |
37
|
|
|
|
|
|
|
{ |
38
|
0
|
0
|
|
|
|
0
|
if(eval { $got->isa('Path::Tiny') }) |
|
0
|
0
|
|
|
|
0
|
|
39
|
|
|
|
|
|
|
{ |
40
|
0
|
|
|
|
|
0
|
return $got->slurp_raw; |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
0
|
elsif(eval { $got->isa('Path::Class::File') }) |
43
|
|
|
|
|
|
|
{ |
44
|
0
|
|
|
|
|
0
|
return $got->slurp(iomode => '<:unix'); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
8
|
|
|
|
|
28
|
return Encode::encode("UTF-8", $got); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub deltas |
52
|
|
|
|
|
|
|
{ |
53
|
8
|
|
|
8
|
1
|
48
|
my($self, %p) = @_; |
54
|
8
|
|
|
|
|
21
|
my($got, $convert) = @p{'got','convert','seen'}; |
55
|
|
|
|
|
|
|
|
56
|
8
|
|
|
|
|
19
|
my $check = $convert->($self->{+INPUT}); |
57
|
|
|
|
|
|
|
|
58
|
8
|
|
|
|
|
454
|
my $got_root_ref = eval { |
59
|
8
|
|
|
|
|
23
|
$self->{+JSON}->decode($self->_convert_got($got)); |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
8
|
|
|
|
|
535
|
my $pointer = $self->{+POINTER}; |
63
|
8
|
100
|
|
|
|
28
|
my $id = [ META => $pointer eq '' ? 'JSON' : "JSON $pointer" ]; |
64
|
|
|
|
|
|
|
|
65
|
8
|
100
|
|
|
|
22
|
if(my $error = "$@") |
66
|
|
|
|
|
|
|
{ |
67
|
1
|
|
|
|
|
4
|
my $check = $convert->('valid json'); |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
63
|
$error =~ s/ at \S+ line [0-9]+\.//; |
70
|
1
|
|
|
|
|
5
|
return $check->delta_class->new( |
71
|
|
|
|
|
|
|
verified => undef, |
72
|
|
|
|
|
|
|
id => $id, |
73
|
|
|
|
|
|
|
got => undef, |
74
|
|
|
|
|
|
|
check => $check, |
75
|
|
|
|
|
|
|
exception => "invalid json: $error", |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
7
|
|
|
|
|
13
|
my $got_ref; |
80
|
|
|
|
|
|
|
my $exists; |
81
|
|
|
|
|
|
|
|
82
|
7
|
50
|
|
|
|
31
|
if(JSON::Pointer->contains($got_root_ref, $pointer)) |
83
|
|
|
|
|
|
|
{ |
84
|
7
|
|
|
|
|
653
|
$exists = 1; |
85
|
7
|
|
|
|
|
21
|
$got_ref = JSON::Pointer->get($got_root_ref, $pointer); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
else |
88
|
|
|
|
|
|
|
{ |
89
|
0
|
|
|
|
|
0
|
$exists = 0; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
7
|
|
|
|
|
476
|
my $delta = $check->run( |
93
|
|
|
|
|
|
|
id => $id, |
94
|
|
|
|
|
|
|
got => $got_ref, |
95
|
|
|
|
|
|
|
exists => $exists, |
96
|
|
|
|
|
|
|
convert => $convert, |
97
|
|
|
|
|
|
|
seen => {}, |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
|
100
|
7
|
100
|
|
|
|
1110
|
$delta ? $delta : (); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |