blib/lib/JSON/Pointer/Syntax.pm

filter: Statementstmt 100% 46 / 46 Branchbran 100% 10 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 5 / 5 totaltotal 100% 77 / 77 CC 7 SCAR 8.8
CC
7
Cov
100%
tokenize
5.0
as_pointer
2.0
is_array_numeric_index
2.0
CRAP 2.4
« Build ↑ Summary _build/lib/MyBuilder.pm »
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
BranchTrueFalseTotal
if ($pointer =~ s[/($JSON::Pointer::Syntax::REGEX_REFERENCE_TOKEN)][]) 201 156 357
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
BranchTrueFalseTotal
unless ($orig_pointer eq "" or $pointer eq "") 3 153 156
Condition100%3/3
$orig_pointer eq "" or $pointer eq ""
l!l&&r!l&&!r
141393
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 ""
ABresult
1X1
011
000
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
BranchTrueFalseTotal
wantarray ? : 141 12 153
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
BranchTrueFalseTotal
@$tokens > 0 ? : 11 1 12
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
BranchTrueFalseTotal
$token =~ /^$JSON::Pointer::Syntax::REGEX_ARRAY_INDEX$/ ? : 47 12 59
78 }
79  
80 16 1;
81  
82 __END__
« Build ↑ Summary _build/lib/MyBuilder.pm »