Marpa/Semantics.pm

filter: Statementstmt 100% 45 / 45 Branchbran 100% 14 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 7 totaltotal 91.1% 72 / 79 CC 8 SCAR 6.4
CC
8
Cov
100%
array_index_dereferencing
3.0
object_name_dereferencing
3.0
next_array_index_dereferencing
2.0
CRAP 1.9
↑ Summary Marpa.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package JSON::Pointer::Marpa::Semantics;
5  
6 2 ▶use subs qw( _index_exists _member_exists );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use constant { ## no critic (ProhibitConstantPragma)
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 EMPTY => '',
10 SLASH => '/',
11 TILDE => '~'
12 2 };
13  
14 # This is a rule evaluation closure of a quantified rule
15 # https://metacpan.org/pod/distribution/Marpa-R2/pod/Semantics.pod#Quantified-rule-nodes
16 48 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
17 48 my ( $class, $crv ) = @_; # crv == currently referenced value
18  
19 48 bless { crv => $crv }, $class
20 }
21  
22 57 ▶sub concat {
Subroutine concat: called CC=1 SCAR=0.0
Pod undocumented
23 57 shift;
24 57 join '', @_
25 }
26  
27 20 ▶sub array_index_dereferencing {
Subroutine array_index_dereferencing: called CC=3 SCAR=11.0
Pod undocumented
28 20 my ( $self, $index ) = @_;
29  
30 20 my $crv = $self->get_crv;
31 20 my $crt = ref $crv; # crt == currently referenced type
32 20 ▶ if ( $crt eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($crt eq 'ARRAY') { } 17 3 20
elsif ($crt eq 'HASH') { } 2 1 3
33 17 $self->set_crv( _index_exists( $crv, $index ) )
34 } elsif ( $crt eq 'HASH' ) {
35 2 $self->set_crv( _member_exists( $crv, $index ) )
36 } else {
37 1 Marpa::R2::Context::bail(
38 "Currently referenced type '$crt' isn't a JSON structured type (array or object)!"
39 )
40 }
41  
42 undef
43 16 }
44  
45 2 ▶sub next_array_index_dereferencing {
Subroutine next_array_index_dereferencing: called CC=2 SCAR=6.9
Pod undocumented
46 2 my ( $self, $next_index ) = @_;
47  
48 2 my $crv = $self->get_crv;
49 ref $crv eq 'ARRAY'
50 ? Marpa::R2::Context::bail(
51 "Handling of '$next_index' array index isn't implemented!" )
52 2 ▶ : $self->set_crv( $crv->{ $next_index } );
Branch: 1 branch
BranchTrueFalseTotal
ref $crv eq 'ARRAY' ? : 1 1 2
53  
54 undef
55 1 }
56  
57 59 ▶sub object_name_dereferencing {
Subroutine object_name_dereferencing: called CC=3 SCAR=11.0
Pod undocumented
58 59 my ( $self, $member ) = @_;
59 59 ▶ $member = '' if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 2 57 59
60  
61 59 my $crv = $self->get_crv;
62 59 my $crt = ref $crv; # crt == currently referenced type
63 59 ▶ Marpa::R2::Context::bail(
Branch: 1 branch
BranchTrueFalseTotal
unless $crt eq "HASH" 2 57 59
64 "Currently referenced type '$crt' isn't a JSON object!" )
65 unless $crt eq 'HASH';
66 57 $self->set_crv( _member_exists( $crv, $member ) );
67  
68 undef
69 55 }
70  
71 72 ▶sub set_crv {
Subroutine set_crv: called CC=1 SCAR=0.0
Pod undocumented
72 72 my ( $self, $crv ) = @_;
73  
74 72 $self->{ crv } = $crv;
75  
76 undef
77 72 }
78  
79 120 ▶sub get_crv {
Subroutine get_crv: called CC=1 SCAR=0.0
Pod undocumented
80 120 my ( $self ) = @_;
81  
82 $self->{ crv }
83 120 }
84  
85 17 ▶sub _index_exists ( $$ ) {
Subroutine _index_exists: called CC=2 SCAR=6.9
86 17 my ( $crv, $index ) = @_;
87  
88 17 ▶ $index < @$crv
Branch: 1 branch
BranchTrueFalseTotal
$index < @$crv ? : 15 2 17
89 ? $crv->[ $index ]
90 : Marpa::R2::Context::bail(
91 "JSON array has been accessed with an index $index that is greater than or equal to the size of the array!"
92 )
93 }
94  
95 59 ▶sub _member_exists ( $$ ) {
Subroutine _member_exists: called CC=2 SCAR=6.9
96 59 my ( $crv, $member ) = @_;
97  
98 exists $crv->{ $member }
99 59 ▶ ? $crv->{ $member }
Branch: 1 branch
BranchTrueFalseTotal
exists $crv->{$member} ? : 56 3 59
100 : Marpa::R2::Context::bail(
101 "JSON object has been accessed with a member '$member' that does not exist!" )
102 }
103  
104 2 1
↑ Summary Marpa.pm »