blib/lib/Logic/Relational/Goal/Guard.pm

filter: Statementstmt 83.3% 30 / 36 Branchbran 66.6% 4 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 6 / 9 Podpod 50.0% 3 / 6 totaltotal 70.9% 44 / 62 CC 7 SCAR 15.4
CC
7
Cov
78%
is_ground
12.0
expand
5.0
vars
2.0
CRAP 4.7
« blib/lib/Logic/Relational/Goal/CellAt.pm ↑ Summary blib/lib/Logic/Relational/Goal/Any.pm »
1 package Logic::Relational::Goal::Guard;
2  
3 30 ▶use v5.38;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 30 ▶use parent 'Logic::Relational::Goal';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Logic::Relational::Goal::Guard - Evaluates a deterministic Perl test block.
10  
11 =cut
12  
13 97 ▶sub new ( $class, $vars, $code ) {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
14 97 return bless { vars => $vars, code => $code }, $class;
15 }
16  
17 0 ▶sub vars ($self) { return $self->{vars}; }
Subroutine vars: not called CC=1 SCAR=6.9
Pod undocumented
18 0 ▶sub code ($self) { return $self->{code}; }
Subroutine code: not called CC=1 SCAR=6.9
Pod undocumented
19  
20 68 ▶sub expand ( $self, %args ) {
Subroutine expand: called CC=5 SCAR=16.1
Pod documented
21 68 my $subst = $args{substitution};
22 68 my $remaining = $args{remaining};
23 68 my $state = $args{state};
24  
25 # Verify all referenced variables are ground
26 68 for my $var ( @{ $self->{vars} } ) {
27 133 my $walked = $subst->walk($var);
28 133 ▶ if ( ref($walked) eq 'Logic::Relational::Variable' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $walked eq "Logic::Relational::Variable") 1 132 133
29 1 die "Guard attempted to read unbound logical variable \$"
30 . $var->name . "\n";
31 }
32 }
33  
34 # Reify values
35 67 my @vals = map { $subst->reify($_) } @{ $self->{vars} };
36  
37 # Run the user code block
38 67 my $ok = $self->{code}->(@vals);
39  
40 67 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) 43 24 67
41 43 my $succ = $state->derive( goals => $remaining, );
42 43 ▶ return $succ // ();
Condition33%1/3
$succ // ()
l!l&&r!l&&!r
4300
MC/DC0%0/2
$succ // ()
$succ ()
Truth table33%1/3
A // B
A= $succB= ()
ABresult
1X1
011
000
43 }
44 24 return ();
45 }
46  
47 5 ▶sub freshen ( $self, $var_map ) {
Subroutine freshen: called CC=1 SCAR=0.0
Pod documented
48 5 my @fresh_vars = map { $_->freshen($var_map) } @{ $self->{vars} };
49 5 return ref($self)->new( \@fresh_vars, $self->{code} );
50 }
51  
52 0 ▶sub is_ground ( $self, $subst ) {
Subroutine is_ground: not called CC=3 SCAR=24.8
Pod documented
53 0 for my $var ( @{ $self->{vars} } ) {
54 0 ▶ return 0 unless $self->term_is_ground( $var, $subst );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->term_is_ground($var, $subst) 0 0 0
55 }
56 0 return 1;
57 }
58  
59 30 1;
« blib/lib/Logic/Relational/Goal/CellAt.pm ↑ Summary blib/lib/Logic/Relational/Goal/Any.pm »