line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Compare::JSON::Pointer; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
58
|
|
4
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
64
|
|
5
|
2
|
|
|
2
|
|
11
|
use Test2::Util::HashBase qw( pointer input json ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
14
|
|
6
|
2
|
|
|
2
|
|
1286
|
use JSON::Pointer; |
|
2
|
|
|
|
|
41075
|
|
|
2
|
|
|
|
|
71
|
|
7
|
2
|
|
|
2
|
|
17
|
use Encode (); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
42
|
|
8
|
2
|
|
|
2
|
|
820
|
use parent 'Test2::Compare::Base'; |
|
2
|
|
|
|
|
571
|
|
|
2
|
|
|
|
|
22
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: Representation of a hash or array reference pointed to by a JSON pointer during deep comparison. |
11
|
|
|
|
|
|
|
our $VERSION = '0.01'; # VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
1
|
1836
|
sub operator { 'JSON PTR' } |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub name |
17
|
|
|
|
|
|
|
{ |
18
|
3
|
|
|
3
|
1
|
132
|
my($self) = @_; |
19
|
3
|
|
|
|
|
12
|
my($input, $pointer) = ($self->{+INPUT}, $self->{+POINTER}); |
20
|
3
|
100
|
|
|
|
21
|
$pointer eq '' ? "$input" : "$pointer $input"; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub verify |
24
|
|
|
|
|
|
|
{ |
25
|
8
|
|
|
8
|
1
|
2557
|
my($self, %params) = @_; |
26
|
8
|
|
|
|
|
28
|
my($got, $exists) = @params{'got','exists'}; |
27
|
|
|
|
|
|
|
|
28
|
8
|
50
|
|
|
|
30
|
return 0 unless $exists; |
29
|
8
|
|
|
|
|
31
|
return 1; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _convert_got |
33
|
|
|
|
|
|
|
{ |
34
|
8
|
|
|
8
|
|
22
|
my(undef, $got) = @_; |
35
|
|
|
|
|
|
|
|
36
|
8
|
50
|
|
|
|
30
|
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
|
|
|
|
|
33
|
return Encode::encode("UTF-8", $got); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub deltas |
52
|
|
|
|
|
|
|
{ |
53
|
8
|
|
|
8
|
1
|
72
|
my($self, %p) = @_; |
54
|
8
|
|
|
|
|
25
|
my($got, $convert) = @p{'got','convert','seen'}; |
55
|
|
|
|
|
|
|
|
56
|
8
|
|
|
|
|
56
|
my $check = $convert->($self->{+INPUT}); |
57
|
|
|
|
|
|
|
|
58
|
8
|
|
|
|
|
701
|
my $got_root_ref = eval { |
59
|
8
|
|
|
|
|
40
|
$self->{+JSON}->decode($self->_convert_got($got)); |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
8
|
|
|
|
|
817
|
my $pointer = $self->{+POINTER}; |
63
|
8
|
100
|
|
|
|
38
|
my $id = [ META => $pointer eq '' ? 'JSON' : "JSON $pointer" ]; |
64
|
|
|
|
|
|
|
|
65
|
8
|
100
|
|
|
|
35
|
if(my $error = "$@") |
66
|
|
|
|
|
|
|
{ |
67
|
1
|
|
|
|
|
3
|
my $check = $convert->('valid json'); |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
62
|
$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
|
|
|
|
|
18
|
my $got_ref; |
80
|
|
|
|
|
|
|
my $exists; |
81
|
|
|
|
|
|
|
|
82
|
7
|
50
|
|
|
|
39
|
if(JSON::Pointer->contains($got_root_ref, $pointer)) |
83
|
|
|
|
|
|
|
{ |
84
|
7
|
|
|
|
|
984
|
$exists = 1; |
85
|
7
|
|
|
|
|
27
|
$got_ref = JSON::Pointer->get($got_root_ref, $pointer); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
else |
88
|
|
|
|
|
|
|
{ |
89
|
0
|
|
|
|
|
0
|
$exists = 0; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
7
|
|
|
|
|
834
|
my $delta = $check->run( |
93
|
|
|
|
|
|
|
id => $id, |
94
|
|
|
|
|
|
|
got => $got_ref, |
95
|
|
|
|
|
|
|
exists => $exists, |
96
|
|
|
|
|
|
|
convert => $convert, |
97
|
|
|
|
|
|
|
seen => {}, |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
|
100
|
7
|
100
|
|
|
|
1466
|
$delta ? $delta : (); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |