line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::Pointer::Syntax; |
2
|
|
|
|
|
|
|
|
3
|
16
|
|
|
16
|
|
152491
|
use 5.008_001; |
|
16
|
|
|
|
|
60
|
|
|
16
|
|
|
|
|
765
|
|
4
|
16
|
|
|
16
|
|
101
|
use strict; |
|
16
|
|
|
|
|
32
|
|
|
16
|
|
|
|
|
637
|
|
5
|
16
|
|
|
16
|
|
87
|
use warnings; |
|
16
|
|
|
|
|
57
|
|
|
16
|
|
|
|
|
517
|
|
6
|
|
|
|
|
|
|
|
7
|
16
|
|
|
16
|
|
86
|
use Exporter qw(import); |
|
16
|
|
|
|
|
22
|
|
|
16
|
|
|
|
|
590
|
|
8
|
16
|
|
|
16
|
|
2918
|
use JSON::Pointer::Context; |
|
16
|
|
|
|
|
82
|
|
|
16
|
|
|
|
|
677
|
|
9
|
16
|
|
|
16
|
|
3426
|
use JSON::Pointer::Exception qw(:all); |
|
16
|
|
|
|
|
32
|
|
|
16
|
|
|
|
|
20610
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
13
|
|
|
|
|
|
|
escape_reference_token |
14
|
|
|
|
|
|
|
unescape_reference_token |
15
|
|
|
|
|
|
|
is_array_numeric_index |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $REGEX_ESCAPED = qr{~[01]}; |
19
|
|
|
|
|
|
|
our $REGEX_UNESCAPED = qr{[\x{00}-\x{2E}\x{30}-\x{7D}\x{7F}-\x{10FFFF}]}; |
20
|
|
|
|
|
|
|
our $REGEX_REFERENCE_TOKEN = qr{(?:$REGEX_ESCAPED|$REGEX_UNESCAPED)*}; |
21
|
|
|
|
|
|
|
our $REGEX_ARRAY_INDEX = qr{(?:0|[1-9][0-9]*)}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub escape_reference_token { |
24
|
15
|
|
|
15
|
1
|
1666
|
my $unescaped_reference_token = shift; |
25
|
|
|
|
|
|
|
|
26
|
15
|
|
|
|
|
35
|
$unescaped_reference_token =~ s/~/~0/g; |
27
|
15
|
|
|
|
|
22
|
$unescaped_reference_token =~ s/\x2F/~1/g; |
28
|
|
|
|
|
|
|
|
29
|
15
|
|
|
|
|
66
|
return $unescaped_reference_token; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub unescape_reference_token { |
33
|
203
|
|
|
203
|
1
|
1953
|
my $escaped_reference_token = shift; |
34
|
|
|
|
|
|
|
|
35
|
203
|
|
|
|
|
339
|
$escaped_reference_token =~ s/~1/\x2F/g; |
36
|
203
|
|
|
|
|
290
|
$escaped_reference_token =~ s/~0/~/g; |
37
|
|
|
|
|
|
|
|
38
|
203
|
|
|
|
|
1440
|
return $escaped_reference_token; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub tokenize { |
42
|
155
|
|
|
155
|
1
|
7984
|
my ($class, $pointer) = @_; |
43
|
155
|
|
|
|
|
307
|
my @tokens; |
44
|
|
|
|
|
|
|
|
45
|
155
|
|
|
|
|
233
|
my $orig_pointer = $pointer; |
46
|
|
|
|
|
|
|
|
47
|
155
|
|
|
|
|
2159
|
while ($pointer =~ s{/($REGEX_REFERENCE_TOKEN)}{}) { |
48
|
200
|
|
|
|
|
601
|
my $token = $1; |
49
|
200
|
|
|
|
|
458
|
push @tokens => unescape_reference_token($token); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
155
|
100
|
100
|
|
|
1129
|
unless ($orig_pointer eq "" || $pointer eq "") { |
53
|
3
|
|
|
|
|
9
|
JSON::Pointer::Exception->throw( |
54
|
|
|
|
|
|
|
code => ERROR_INVALID_POINTER_SYNTAX, |
55
|
|
|
|
|
|
|
context => JSON::Pointer::Context->new( |
56
|
|
|
|
|
|
|
pointer => $orig_pointer, |
57
|
|
|
|
|
|
|
), |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
152
|
100
|
|
|
|
1093
|
return wantarray ? @tokens : [ @tokens ]; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub as_pointer { |
65
|
12
|
|
|
12
|
1
|
5522
|
my ($class, $tokens) = @_; |
66
|
|
|
|
|
|
|
|
67
|
12
|
|
|
|
|
26
|
return @$tokens > 0 ? "/" . join( |
68
|
|
|
|
|
|
|
"/", |
69
|
12
|
100
|
|
|
|
49
|
map { escape_reference_token($_) } |
70
|
|
|
|
|
|
|
@$tokens |
71
|
|
|
|
|
|
|
) : ""; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub is_array_numeric_index { |
76
|
58
|
|
|
58
|
1
|
4013
|
my $token = shift; |
77
|
58
|
100
|
|
|
|
1203
|
return $token =~ m/^$REGEX_ARRAY_INDEX$/ ? 1 : 0; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |