| 1 | package JSON::Pointer::Syntax; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 16 | ▶ | use 5.008_001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 16 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 16 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 16 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 16 | ▶ | use JSON::Pointer::Context; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 16 | ▶ | use JSON::Pointer::Exception qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 16 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||
| 12 | 16 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 13 | escape_reference_token | ||||||||||||||||||||||||||||
| 14 | unescape_reference_token | ||||||||||||||||||||||||||||
| 15 | is_array_numeric_index | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 16 | our $REGEX_ESCAPED = qr{~[01]}; | |||||||||||||||||||||||||||
| 19 | 16 | our $REGEX_UNESCAPED = qr{[\x{00}-\x{2E}\x{30}-\x{7D}\x{7F}-\x{10FFFF}]}; | |||||||||||||||||||||||||||
| 20 | 16 | our $REGEX_REFERENCE_TOKEN = qr{(?:$REGEX_ESCAPED|$REGEX_UNESCAPED)*}; | |||||||||||||||||||||||||||
| 21 | 16 | our $REGEX_ARRAY_INDEX = qr{(?:0|[1-9][0-9]*)}; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub escape_reference_token { | ||||||||||||||||||||||||||||
| 24 | 15 | ▶ | my $unescaped_reference_token = shift; | ||||||||||||||||||||||||||
|
Subroutine
escape_reference_token: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 15 | $unescaped_reference_token =~ s/~/~0/g; | |||||||||||||||||||||||||||
| 27 | 15 | $unescaped_reference_token =~ s/\x2F/~1/g; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 15 | return $unescaped_reference_token; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub unescape_reference_token { | ||||||||||||||||||||||||||||
| 33 | 204 | ▶ | my $escaped_reference_token = shift; | ||||||||||||||||||||||||||
|
Subroutine
unescape_reference_token: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 204 | $escaped_reference_token =~ s/~1/\x2F/g; | |||||||||||||||||||||||||||
| 36 | 204 | $escaped_reference_token =~ s/~0/~/g; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 204 | return $escaped_reference_token; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | sub tokenize { | ||||||||||||||||||||||||||||
| 42 | 156 | ▶ | my ($class, $pointer) = @_; | ||||||||||||||||||||||||||
|
Subroutine
tokenize: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 156 | my @tokens; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 156 | my $orig_pointer = $pointer; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 156 | ▶ | while ($pointer =~ s{/($REGEX_REFERENCE_TOKEN)}{}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 201 | my $token = $1; | |||||||||||||||||||||||||||
| 49 | 201 | push @tokens => unescape_reference_token($token); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 156 | ▶ | unless ($orig_pointer eq "" || $pointer eq "") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$orig_pointer eq "" or $pointer eq ""
MC/DC100%2/2
$orig_pointer eq "" or $pointer eq ""
$orig_pointer eq ""
$pointer eq ""
Truth table100%3/3
A or B
A= $orig_pointer eq ""B= $pointer eq ""
| |||||||||||||||||||||||||||||
| 53 | 3 | 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 | 153 | ▶ | return wantarray ? @tokens : [ @tokens ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | sub as_pointer { | ||||||||||||||||||||||||||||
| 65 | 12 | ▶ | my ($class, $tokens) = @_; | ||||||||||||||||||||||||||
|
Subroutine
as_pointer: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | return @$tokens > 0 ? "/" . join( | ||||||||||||||||||||||||||||
| 68 | "/", | ||||||||||||||||||||||||||||
| 69 | 12 | ▶ | map { escape_reference_token($_) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | @$tokens | ||||||||||||||||||||||||||||
| 71 | ) : ""; | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | sub is_array_numeric_index { | ||||||||||||||||||||||||||||
| 76 | 59 | ▶ | my $token = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_array_numeric_index: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 59 | ▶ | return $token =~ m/^$REGEX_ARRAY_INDEX$/ ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 16 | 1; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | __END__ | ||||||||||||||||||||||||||||