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

filter: Statementstmt 65.5% 38 / 58 Branchbran 36.6% 11 / 30 Conditioncond 25.0% 2 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 81.8% 9 / 11 Podpod 60.0% 3 / 5 totaltotal 53.8% 63 / 117 CC 23 SCAR 39.3
CC
23
Cov
53%
_first_unbound_variable
114.4
_first_unbound_var_in_term
8.1
expand
6.1
CRAP 51.2
« blib/lib/Logic/Relational/Goal/Identical.pm ↑ Summary lib/Logic/Relational/Syntax.pm »
1 package Logic::Relational::Goal::Not;
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 30 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Logic::Relational::Goal::Not - Negation as failure (not) goal.
11  
12 =cut
13  
14 36 ▶sub new ( $class, $inner_goal ) {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
15 36 return bless { inner_goal => $inner_goal }, $class;
16 }
17  
18 0 ▶sub inner_goal ($self) { return $self->{inner_goal}; }
Subroutine inner_goal: not called CC=1 SCAR=6.9
Pod undocumented
19  
20 20 ▶sub expand ( $self, %args ) {
Subroutine expand: called CC=6 SCAR=18.1
Pod documented
21 20 my $predicates = $args{predicates};
22 20 my $subst = $args{substitution};
23 20 my $remaining = $args{remaining};
24 20 my $program = $args{program};
25 20 my $state = $args{state};
26  
27 # Floundering check
28 20 ▶ unless ( $self->{inner_goal}->is_ground($subst) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inner_goal"}->is_ground($subst)) 1 19 20
29 my $unbound =
30 1 $self->_first_unbound_variable( $self->{inner_goal}, $subst );
31 1 ▶ my $var_name = $unbound ? $unbound->name : 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
$unbound ? : 1 0 1
32 1 croak "Negated goal contains unbound variable \$" . $var_name . "\n";
33 }
34  
35 # Run inner query with current substitution snapshot
36 19 require Logic::Relational::Query;
37 my $inner_query = Logic::Relational::Query->new(
38 program => $program,
39 goals => [ $self->{inner_goal} ],
40 predicates => $predicates,
41 generators => $args{generators} // {},
42 19 ▶ substitution => $subst,
Condition50%1/2
$args{"generators"} // {}
l!l
190
MC/DC0%0/1
$args{"generators"} // {}
$args{"generators"}
Truth table50%1/2
A
A= $args{"generators"}
Aresult
11
00
43 table_cache => $state->table_cache,
44 );
45  
46 19 ▶ if ( $inner_query->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inner_query->next) { } 5 14 19
47  
48 # Inner goal succeeded, so negation fails
49 5 return ();
50 }
51 else {
52 # Inner goal failed, so negation succeeds
53 14 my $succ = $state->derive( goals => $remaining, );
54 14 ▶ return $succ // ();
Condition33%1/3
$succ // ()
l!l&&r!l&&!r
1400
MC/DC0%0/2
$succ // ()
$succ ()
Truth table33%1/3
A // B
A= $succB= ()
ABresult
1X1
011
000
55 }
56 }
57  
58 10 ▶sub freshen ( $self, $var_map ) {
Subroutine freshen: called CC=1 SCAR=0.0
Pod documented
59 10 return ref($self)->new( $self->{inner_goal}->freshen($var_map) );
60 }
61  
62 0 ▶sub is_ground ( $self, $subst ) {
Subroutine is_ground: not called CC=1 SCAR=6.9
Pod documented
63 0 return $self->{inner_goal}->is_ground($subst);
64 }
65  
66 1 ▶sub _first_unbound_variable ( $self, $goal, $subst ) {
Subroutine _first_unbound_variable: called CC=14 SCAR=47.4
67 1 ▶ if ( ref($goal) eq 'Logic::Relational::Goal::Call' ) { ## no critic (ProhibitCascadingIfElse)
Branch: 5 branches
BranchTrueFalseTotal
if (ref $goal eq 'Logic::Relational::Goal::Call') { } 1 0 1
elsif (ref $goal eq 'Logic::Relational::Goal::Unify') { } 0 0 0
elsif (ref $goal eq 'Logic::Relational::Goal::All' or ref $goal eq 'Logic::Relational::Goal::Any') { } 0 0 0
elsif (ref $goal eq 'Logic::Relational::Goal::Not') { } 0 0 0
elsif (ref $goal eq 'Logic::Relational::Goal::Guard') { } 0 0 0
68 1 for my $arg ( @{ $goal->args } ) {
69 2 my $v = $self->_first_unbound_var_in_term( $arg, $subst );
70 2 ▶ return $v if $v;
Branch: 1 branch
BranchTrueFalseTotal
if $v 1 1 2
71 }
72 }
73 elsif ( ref($goal) eq 'Logic::Relational::Goal::Unify' ) {
74 0 my $v = $self->_first_unbound_var_in_term( $goal->left, $subst );
75 0 ▶ return $v if $v;
Branch: 1 branch
BranchTrueFalseTotal
if $v 0 0 0
76 0 return $self->_first_unbound_var_in_term( $goal->right, $subst );
77 }
78 ▶ elsif (ref($goal) eq 'Logic::Relational::Goal::All'
Condition0%0/3
ref $goal eq "Logic::Relational::Goal::All" or ref $goal eq "Logic::Relational::Goal::Any"
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $goal eq "Logic::Relational::Goal::All" or ref $goal eq "Logic::Relational::Goal::Any"
ref $goal eq "Logic::Relational::Goal::All" ref $goal eq "Logic::Relational::Goal::Any"
Truth table0%0/3
A or B
A= ref $goal eq "Logic::Relational::Goal::All"B= ref $goal eq "Logic::Relational::Goal::Any"
ABresult
1X1
011
000
79 || ref($goal) eq 'Logic::Relational::Goal::Any' )
80 {
81 0 for my $g ( @{ $goal->goals } ) {
82 0 my $v = $self->_first_unbound_variable( $g, $subst );
83 0 ▶ return $v if $v;
Branch: 1 branch
BranchTrueFalseTotal
if $v 0 0 0
84 }
85 }
86 elsif ( ref($goal) eq 'Logic::Relational::Goal::Not' ) {
87 0 return $self->_first_unbound_variable( $goal->inner_goal, $subst );
88 }
89 elsif ( ref($goal) eq 'Logic::Relational::Goal::Guard' ) {
90 0 for my $var ( @{ $goal->vars } ) {
91 0 my $walked = $subst->walk($var);
92 0 ▶ if ( ref($walked) eq 'Logic::Relational::Variable' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $walked eq "Logic::Relational::Variable") 0 0 0
93 0 return $walked;
94 }
95 }
96 }
97 0 return undef;
98 }
99  
100 2 ▶sub _first_unbound_var_in_term ( $self, $term, $subst ) {
Subroutine _first_unbound_var_in_term: called CC=5 SCAR=20.9
101 2 $term = $subst->walk($term);
102 2 ▶ if ( ref($term) eq 'Logic::Relational::Variable' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $term eq 'Logic::Relational::Variable') { } 1 1 2
elsif (ref $term eq 'Logic::Relational::Term') { } 0 1 1
103 1 return $term;
104 }
105 elsif ( ref($term) eq 'Logic::Relational::Term' ) {
106 0 for my $arg ( @{ $term->args } ) {
107 0 my $v = $self->_first_unbound_var_in_term( $arg, $subst );
108 0 ▶ return $v if $v;
Branch: 1 branch
BranchTrueFalseTotal
if $v 0 0 0
109 }
110 }
111 1 return undef;
112 }
113  
114 30 1;
« blib/lib/Logic/Relational/Goal/Identical.pm ↑ Summary lib/Logic/Relational/Syntax.pm »