Pointer/Syntax.pm

filter: Statementstmt 100% 48 / 48 Branchbran 100% 12 / 12 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 5 / 5 totaltotal 100% 81 / 81 CC 8 SCAR 9.4
CC
8
Cov
100%
tokenize
5.0
as_pointer
3.0
is_array_numeric_index
2.0
CRAP 2.6
« Pointer.pm ↑ Summary Pointer/Context.pm »
1 package JSON::Pointer::Syntax;
2  
3 17 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 17 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 17 ▶use JSON::Pointer::Context;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 17 ▶use JSON::Pointer::Exception qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 17 our $VERSION = '0.07';
12 17 our @EXPORT_OK = qw(
13 escape_reference_token
14 unescape_reference_token
15 is_array_numeric_index
16 );
17  
18 17 our $REGEX_ESCAPED = qr{~[01]};
19 17 our $REGEX_UNESCAPED = qr{[\x{00}-\x{2E}\x{30}-\x{7D}\x{7F}-\x{10FFFF}]};
20 17 our $REGEX_REFERENCE_TOKEN = qr{(?:$REGEX_ESCAPED|$REGEX_UNESCAPED)*};
21 17 our $REGEX_ARRAY_INDEX = qr{(?:0|[1-9][0-9]*)};
22  
23 33 ▶sub escape_reference_token {
Subroutine escape_reference_token: called CC=1 SCAR=0.0
Pod documented
24 33 my $unescaped_reference_token = shift;
25  
26 33 $unescaped_reference_token =~ s/~/~0/g;
27 33 $unescaped_reference_token =~ s/\x2F/~1/g;
28  
29 33 return $unescaped_reference_token;
30 }
31  
32 243 ▶sub unescape_reference_token {
Subroutine unescape_reference_token: called CC=1 SCAR=0.0
Pod documented
33 243 my $escaped_reference_token = shift;
34  
35 243 $escaped_reference_token =~ s/~1/\x2F/g;
36 243 $escaped_reference_token =~ s/~0/~/g;
37  
38 243 return $escaped_reference_token;
39 }
40  
41 178 ▶sub tokenize {
Subroutine tokenize: called CC=5 SCAR=16.1
Pod documented
42 178 my ($class, $pointer) = @_;
43 178 my @tokens;
44  
45 178 my $orig_pointer = $pointer;
46  
47 178 ▶ while ($pointer =~ s{/($REGEX_REFERENCE_TOKEN)}{}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pointer =~ s[/($JSON::Pointer::Syntax::REGEX_REFERENCE_TOKEN)][]) 240 178 418
48 240 my $token = $1;
49 240 push @tokens => unescape_reference_token($token);
50 }
51  
52 178 ▶ unless ($orig_pointer eq "" || $pointer eq "") {
Branch: 1 branch
BranchTrueFalseTotal
unless ($orig_pointer eq "" or $pointer eq "") 3 175 178
Condition100%3/3
$orig_pointer eq "" or $pointer eq ""
l!l&&r!l&&!r
181573
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 175 ▶ return wantarray ? @tokens : [ @tokens ];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 163 12 175
62 }
63  
64 30 ▶sub as_pointer {
Subroutine as_pointer: called CC=3 SCAR=11.0
Pod documented
65 30 my $class = shift;
66 30 ▶ my @tokens = (ref $_[0] eq "ARRAY") ? @{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 12 18 30
67  
68 return @tokens > 0 ? "/" . join(
69 "/",
70 30 ▶ map { escape_reference_token($_) }
Branch: 1 branch
BranchTrueFalseTotal
@tokens > 0 ? : 26 4 30
71 @tokens
72 ) : "";
73 }
74  
75 62 ▶sub is_array_numeric_index {
Subroutine is_array_numeric_index: called CC=2 SCAR=6.9
Pod documented
76 62 my $token = shift;
77 62 ▶ return $token =~ m/^$REGEX_ARRAY_INDEX$/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$token =~ /^$JSON::Pointer::Syntax::REGEX_ARRAY_INDEX$/ ? : 50 12 62
78 }
79  
80 17 1;
81  
82 __END__
« Pointer.pm ↑ Summary Pointer/Context.pm »