blib/lib/Logic/Relational/Unifier.pm

filter: Statementstmt 79.0% 128 / 162 Branchbran 73.7% 87 / 118 Conditioncond 75.9% 41 / 54 MC/DCmcdc 61.1% 22 / 36 Subroutinesub 100% 11 / 11 Podpod 60.0% 3 / 5 totaltotal 75.6% 292 / 386 CC 87 SCAR 35.0
CC
87
Cov
77%
unify_hashes
78.3
bind_variable
30.9
unify
21.4
CRAP 33.1
« lib/Logic/Relational/Syntax.pm ↑ Summary blib/lib/Logic/Relational/Goal.pm »
1 package Logic::Relational::Unifier;
2  
3 33 ▶use v5.38;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 33 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 33 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 33 ▶use builtin 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 33 ▶no warnings 'experimental::builtin';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 Logic::Relational::Unifier - Performs structural unification of logic terms.
13  
14 =head1 SYNOPSIS
15  
16 use Logic::Relational::Unifier qw(unify);
17 my $new_subst = unify($term1, $term2, $subst);
18  
19 =head1 DESCRIPTION
20  
21 C<Logic::Relational::Unifier> provides structural unification. It implements
22 the standard unification algorithm with an occurs check to prevent infinite terms.
23  
24 =head1 FUNCTIONS
25  
26 =head2 unify
27  
28 Performs unification of two terms under a given C<Logic::Relational::Substitution>.
29 Returns the updated substitution if unification succeeds, or C<undef> if it fails.
30 Raises an exception if the occurs check fails.
31  
32 =head2 bind_variable
33  
34 Binds a variable to a term, checking that the variable does not occur inside
35 the term (occurs check).
36  
37 =head2 occurs_in
38  
39 Helper function. Returns true if the variable ID occurs inside the dereferenced term.
40  
41 =cut
42  
43 33 our @EXPORT_OK = qw(unify);
44 33 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 2523 ▶sub unify ( $left, $right, $subst ) {
Subroutine unify: called CC=20 SCAR=30.6
Pod documented
47 2523 $left = $subst->walk($left);
48 2523 $right = $subst->walk($right);
49  
50 2523 ▶ if ( ref($left) eq 'Logic::Relational::Variable' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $left eq "Logic::Relational::Variable") 899 1624 2523
51 899 return bind_variable( $left, $right, $subst );
52 }
53  
54 1624 ▶ if ( ref($right) eq 'Logic::Relational::Variable' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $right eq "Logic::Relational::Variable") 232 1392 1624
55 232 return bind_variable( $right, $left, $subst );
56 }
57  
58 # Constants
59 1392 ▶ my $is_const_l = !ref($left) || ref($left) eq 'Logic::Relational::Atom';
Condition100%3/3
!ref($left) || ref $left eq 'Logic::Relational::Atom'
l!l&&r!l&&!r
5183871
MC/DC100%2/2
!ref($left) || ref $left eq 'Logic::Relational::Atom'
!ref($left) ref $left eq 'Logic::Relational::Atom'
Truth table100%3/3
not(A) || B
A= !ref($left)B= ref $left eq 'Logic::Relational::Atom'
ABresult
1X1
011
000
60 1392 ▶ my $is_const_r = !ref($right) || ref($right) eq 'Logic::Relational::Atom';
Condition100%3/3
!ref($right) || ref $right eq 'Logic::Relational::Atom'
l!l&&r!l&&!r
5192871
MC/DC100%2/2
!ref($right) || ref $right eq 'Logic::Relational::Atom'
!ref($right) ref $right eq 'Logic::Relational::Atom'
Truth table100%3/3
not(A) || B
A= !ref($right)B= ref $right eq 'Logic::Relational::Atom'
ABresult
1X1
011
000
61  
62 1392 ▶ if ( $is_const_l && $is_const_r ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_const_l and $is_const_r) 521 871 1392
Condition66%2/3
$is_const_l and $is_const_r
!ll&&!rl&&r
8710521
MC/DC50%1/2
$is_const_l and $is_const_r
$is_const_l $is_const_r
Truth table66%2/3
A and B
A= $is_const_lB= $is_const_r
ABresult
0X0
100
111
63 521 ▶ my $val_l = ref($left) ? $left->value : $left;
Branch: 1 branch
BranchTrueFalseTotal
ref $left ? : 3 518 521
64 521 ▶ my $val_r = ref($right) ? $right->value : $right;
Branch: 1 branch
BranchTrueFalseTotal
ref $right ? : 2 519 521
65 521 ▶ return $val_l eq $val_r ? $subst : undef;
Branch: 1 branch
BranchTrueFalseTotal
$val_l eq $val_r ? : 193 328 521
66 }
67  
68 # Compound terms
69 871 ▶ if ( ref($left) eq 'Logic::Relational::Term'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $left eq "Logic::Relational::Term" and ref $right eq "Logic::Relational::Term") 791 80 871
Condition66%2/3
ref $left eq "Logic::Relational::Term" and ref $right eq "Logic::Relational::Term"
!ll&&!rl&&r
800791
MC/DC50%1/2
ref $left eq "Logic::Relational::Term" and ref $right eq "Logic::Relational::Term"
ref $left eq "Logic::Relational::Term" ref $right eq "Logic::Relational::Term"
Truth table66%2/3
A and B
A= ref $left eq "Logic::Relational::Term"B= ref $right eq "Logic::Relational::Term"
ABresult
0X0
100
111
70 && ref($right) eq 'Logic::Relational::Term' )
71 {
72 return undef
73 791 ▶ unless $left->functor eq $right->functor
Branch: 1 branch
BranchTrueFalseTotal
unless $left->functor eq $right->functor and $left->arity == $right->arity 0 791 791
Condition33%1/3
$left->functor eq $right->functor and $left->arity == $right->arity
!ll&&!rl&&r
00791
MC/DC0%0/2
$left->functor eq $right->functor and $left->arity == $right->arity
$left->functor eq $right->functor $left->arity == $right->arity
Truth table33%1/3
A and B
A= $left->functor eq $right->functorB= $left->arity == $right->arity
ABresult
0X0
100
111
74 && $left->arity == $right->arity;
75  
76 791 for my $i ( 0 .. $left->arity - 1 ) {
77 1203 $subst = unify( $left->arg($i), $right->arg($i), $subst );
78 1203 ▶ return undef unless $subst;
Branch: 1 branch
BranchTrueFalseTotal
unless $subst 336 867 1203
79 }
80 455 return $subst;
81 }
82  
83 80 ▶ if ( ref($left) eq 'ARRAY' && ref($right) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $left eq "ARRAY" and ref $right eq "ARRAY") 70 10 80
Condition66%2/3
ref $left eq "ARRAY" and ref $right eq "ARRAY"
!ll&&!rl&&r
10070
MC/DC50%1/2
ref $left eq "ARRAY" and ref $right eq "ARRAY"
ref $left eq "ARRAY" ref $right eq "ARRAY"
Truth table66%2/3
A and B
A= ref $left eq "ARRAY"B= ref $right eq "ARRAY"
ABresult
0X0
100
111
84 70 return unify_arrays( $left, $right, $subst );
85 }
86  
87 10 ▶ if ( ref($left) eq 'HASH' && ref($right) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $left eq "HASH" and ref $right eq "HASH") 10 0 10
Condition33%1/3
ref $left eq "HASH" and ref $right eq "HASH"
!ll&&!rl&&r
0010
MC/DC0%0/2
ref $left eq "HASH" and ref $right eq "HASH"
ref $left eq "HASH" ref $right eq "HASH"
Truth table33%1/3
A and B
A= ref $left eq "HASH"B= ref $right eq "HASH"
ABresult
0X0
100
111
88 10 return unify_hashes( $left, $right, $subst );
89 }
90  
91 0 return undef;
92 }
93  
94 10 ▶sub unify_hashes ( $left, $right, $subst ) { ## no critic (ProhibitExcessComplexity)
Subroutine unify_hashes: called CC=22 SCAR=43.6
Pod undocumented
95 my @slurp_keys_l =
96 10 grep { ref( $left->{$_} ) eq 'Logic::Relational::ArrayRest' }
97 keys %$left;
98 my @slurp_keys_r =
99 10 grep { ref( $right->{$_} ) eq 'Logic::Relational::ArrayRest' }
100 keys %$right;
101  
102 10 ▶ if ( scalar @slurp_keys_l > 1 || scalar @slurp_keys_r > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @slurp_keys_l > 1 or scalar @slurp_keys_r > 1) 1 9 10
Condition66%2/3
scalar @slurp_keys_l > 1 or scalar @slurp_keys_r > 1
l!l&&r!l&&!r
109
MC/DC50%1/2
scalar @slurp_keys_l > 1 or scalar @slurp_keys_r > 1
scalar @slurp_keys_l > 1 scalar @slurp_keys_r > 1
Truth table66%2/3
A or B
A= scalar @slurp_keys_l > 1B= scalar @slurp_keys_r > 1
ABresult
1X1
011
000
103 1 croak
104 "Only one slurp/rest value is allowed in a hash reference pattern";
105 }
106  
107 9 my $slurp_k_l = $slurp_keys_l[0];
108 9 my $slurp_k_r = $slurp_keys_r[0];
109  
110 9 ▶ if ( defined $slurp_k_l && defined $slurp_k_r ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $slurp_k_l and defined $slurp_k_r) { } 0 9 9
elsif (defined $slurp_k_l) { } 2 7 9
elsif (defined $slurp_k_r) { } 0 7 7
Condition66%2/3
defined $slurp_k_l and defined $slurp_k_r
!ll&&!rl&&r
720
MC/DC0%0/2
defined $slurp_k_l and defined $slurp_k_r
defined $slurp_k_l defined $slurp_k_r
Truth table66%2/3
A and B
A= defined $slurp_k_lB= defined $slurp_k_r
ABresult
0X0
100
111
111 0 my %std_keys_l = map { $_ => 1 } grep { $_ ne $slurp_k_l } keys %$left;
112 0 my %std_keys_r = map { $_ => 1 } grep { $_ ne $slurp_k_r } keys %$right;
113  
114 0 for my $k ( keys %std_keys_l ) {
115 0 ▶ return undef unless exists $right->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $right->{$k} 0 0 0
116 0 $subst = unify( $left->{$k}, $right->{$k}, $subst );
117 0 ▶ return undef unless $subst;
Branch: 1 branch
BranchTrueFalseTotal
unless $subst 0 0 0
118 }
119 0 for my $k ( keys %std_keys_r ) {
120 0 ▶ return undef unless exists $left->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $left->{$k} 0 0 0
121 }
122  
123 0 return unify( $left->{$slurp_k_l}->term, $right->{$slurp_k_r}->term,
124 $subst );
125 }
126 elsif ( defined $slurp_k_l ) {
127 2 my %std_keys_l = map { $_ => 1 } grep { $_ ne $slurp_k_l } keys %$left;
128  
129 2 for my $k ( keys %std_keys_l ) {
130 2 ▶ return undef unless exists $right->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $right->{$k} 0 2 2
131 2 $subst = unify( $left->{$k}, $right->{$k}, $subst );
132 2 ▶ return undef unless $subst;
Branch: 1 branch
BranchTrueFalseTotal
unless $subst 0 2 2
133 }
134  
135 my %remainder =
136 2 map { $_ => $right->{$_} }
137 2 grep { !exists $std_keys_l{$_} } keys %$right;
138 2 return unify( $left->{$slurp_k_l}->term, \%remainder, $subst );
139 }
140 elsif ( defined $slurp_k_r ) {
141 0 my %std_keys_r = map { $_ => 1 } grep { $_ ne $slurp_k_r } keys %$right;
142  
143 0 for my $k ( keys %std_keys_r ) {
144 0 ▶ return undef unless exists $left->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $left->{$k} 0 0 0
145 0 $subst = unify( $left->{$k}, $right->{$k}, $subst );
146 0 ▶ return undef unless $subst;
Branch: 1 branch
BranchTrueFalseTotal
unless $subst 0 0 0
147 }
148  
149 my %remainder =
150 0 map { $_ => $left->{$_} }
151 0 grep { !exists $std_keys_r{$_} } keys %$left;
152 0 return unify( \%remainder, $right->{$slurp_k_r}->term, $subst );
153 }
154 else {
155 7 ▶ return undef unless scalar keys %$left == scalar keys %$right;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %$left == scalar keys %$right 1 6 7
156 6 for my $k ( keys %$left ) {
157 12 ▶ return undef unless exists $right->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $right->{$k} 0 12 12
158 12 $subst = unify( $left->{$k}, $right->{$k}, $subst );
159 12 ▶ return undef unless $subst;
Branch: 1 branch
BranchTrueFalseTotal
unless $subst 1 11 12
160 }
161 5 return $subst;
162 }
163 }
164  
165 70 ▶sub unify_arrays ( $left, $right, $subst ) {
Subroutine unify_arrays: called CC=16 SCAR=27.8
Pod undocumented
166 70 my $M = scalar @$left;
167 70 my $N = scalar @$right;
168  
169 70 my $i = 0;
170 70 ▶ while ( $i < $M || $i < $N ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $M or $i < $N) 104 12 116
Condition100%3/3
$i < $M or $i < $N
l!l&&r!l&&!r
861812
MC/DC100%2/2
$i < $M or $i < $N
$i < $M $i < $N
Truth table100%3/3
A or B
A= $i < $MB= $i < $N
ABresult
1X1
011
000
171 104 ▶ my $has_rest_l =
Condition100%3/3
$i < $M && ref $left->[$i] eq 'Logic::Relational::ArrayRest'
!ll&&!rl&&r
18824
MC/DC100%2/2
$i < $M && ref $left->[$i] eq 'Logic::Relational::ArrayRest'
$i < $M ref $left->[$i] eq 'Logic::Relational::ArrayRest'
Truth table100%3/3
A && B
A= $i < $MB= ref $left->[$i] eq 'Logic::Relational::ArrayRest'
ABresult
0X0
100
111
172 ( $i < $M && ref( $left->[$i] ) eq 'Logic::Relational::ArrayRest' );
173 104 ▶ my $has_rest_r =
Condition100%3/3
$i < $N && ref $right->[$i] eq 'Logic::Relational::ArrayRest'
!ll&&!rl&&r
176126
MC/DC100%2/2
$i < $N && ref $right->[$i] eq 'Logic::Relational::ArrayRest'
$i < $N ref $right->[$i] eq 'Logic::Relational::ArrayRest'
Truth table100%3/3
A && B
A= $i < $NB= ref $right->[$i] eq 'Logic::Relational::ArrayRest'
ABresult
0X0
100
111
174 ( $i < $N && ref( $right->[$i] ) eq 'Logic::Relational::ArrayRest' );
175  
176 104 ▶ if ( $has_rest_l && $has_rest_r ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($has_rest_l and $has_rest_r) { } 1 103 104
elsif ($has_rest_l) { } 3 100 103
elsif ($has_rest_r) { } 25 75 100
Condition100%3/3
$has_rest_l and $has_rest_r
!ll&&!rl&&r
10031
MC/DC100%2/2
$has_rest_l and $has_rest_r
$has_rest_l $has_rest_r
Truth table100%3/3
A and B
A= $has_rest_lB= $has_rest_r
ABresult
0X0
100
111
177 1 ▶ croak "rest/slurp must be the last element of an array"
Branch: 1 branch
BranchTrueFalseTotal
unless $i == $M - 1 and $i == $N - 1 0 1 1
Condition33%1/3
$i == $M - 1 and $i == $N - 1
!ll&&!rl&&r
001
MC/DC0%0/2
$i == $M - 1 and $i == $N - 1
$i == $M - 1 $i == $N - 1
Truth table33%1/3
A and B
A= $i == $M - 1B= $i == $N - 1
ABresult
0X0
100
111
178 unless $i == $M - 1 && $i == $N - 1;
179 1 return unify( $left->[$i]->term, $right->[$i]->term, $subst );
180 }
181 elsif ($has_rest_l) {
182 3 ▶ croak "rest/slurp must be the last element of an array"
Branch: 1 branch
BranchTrueFalseTotal
unless $i == $M - 1 1 2 3
183 unless $i == $M - 1;
184 2 my $remainder = [ @{$right}[ $i .. $#$right ] ];
185 2 return unify( $left->[$i]->term, $remainder, $subst );
186 }
187 elsif ($has_rest_r) {
188 25 ▶ croak "rest/slurp must be the last element of an array"
Branch: 1 branch
BranchTrueFalseTotal
unless $i == $N - 1 0 25 25
189 unless $i == $N - 1;
190 25 my $remainder = [ @{$left}[ $i .. $#$left ] ];
191 25 return unify( $remainder, $right->[$i]->term, $subst );
192 }
193  
194 75 ▶ if ( $i >= $M || $i >= $N ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $M or $i >= $N) 27 48 75
Condition100%3/3
$i >= $M or $i >= $N
l!l&&r!l&&!r
111648
MC/DC100%2/2
$i >= $M or $i >= $N
$i >= $M $i >= $N
Truth table100%3/3
A or B
A= $i >= $MB= $i >= $N
ABresult
1X1
011
000
195 27 return undef;
196 }
197  
198 48 $subst = unify( $left->[$i], $right->[$i], $subst );
199 48 ▶ return undef unless $subst;
Branch: 1 branch
BranchTrueFalseTotal
unless $subst 2 46 48
200 46 $i++;
201 }
202 12 return $subst;
203 }
204  
205 1131 ▶sub bind_variable ( $var, $val, $subst ) { ## no critic (ProhibitExcessComplexity)
Subroutine bind_variable: called CC=21 SCAR=34.3
Pod documented
206 1131 ▶ if ( ref($val) eq 'Logic::Relational::Variable' && $var->id == $val->id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq "Logic::Relational::Variable" and $var->id == $val->id) 1 1130 1131
Condition100%3/3
ref $val eq "Logic::Relational::Variable" and $var->id == $val->id
!ll&&!rl&&r
9851451
MC/DC100%2/2
ref $val eq "Logic::Relational::Variable" and $var->id == $val->id
ref $val eq "Logic::Relational::Variable" $var->id == $val->id
Truth table100%3/3
A and B
A= ref $val eq "Logic::Relational::Variable"B= $var->id == $val->id
ABresult
0X0
100
111
207 1 return $subst;
208 }
209  
210 1130 ▶ if ( occurs_in( $var->id, $val, $subst ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (occurs_in($var->id, $val, $subst)) 3 1127 1130
211 3 my $var_str = $var->as_string;
212 3 ▶ my $val_str = blessed($val)
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($val) && $val->can('as_string') ? : 1 2 3
Condition66%2/3
builtin::blessed($val) and $val->can("as_string")
!ll&&!rl&&r
201
MC/DC50%1/2
builtin::blessed($val) and $val->can("as_string")
builtin::blessed($val) $val->can("as_string")
Truth table66%2/3
A and B
A= builtin::blessed($val)B= $val->can("as_string")
ABresult
0X0
100
111
213 && $val->can('as_string') ? $val->as_string : "$val";
214 3 croak "Occurs check failed: cannot bind $var_str to $val_str\n";
215 }
216  
217 1127 my $d_var = $subst->{bindings}{ $var->id };
218 1127 my $has_d_var = ( ref($d_var) eq 'Logic::Relational::Domain' );
219  
220 1127 ▶ if ( ref($val) eq 'Logic::Relational::Variable' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $val eq 'Logic::Relational::Variable') { } 145 982 1127
elsif (ref $val eq 'Logic::Relational::Domain') { } 22 960 982
221 145 my $d_val = $subst->{bindings}{ $val->id };
222 145 my $has_d_val = ( ref($d_val) eq 'Logic::Relational::Domain' );
223  
224 145 ▶ if ( $has_d_var && $has_d_val ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($has_d_var and $has_d_val) { } 1 144 145
elsif ($has_d_var) { } 0 144 144
elsif ($has_d_val) { } 12 132 144
Condition66%2/3
$has_d_var and $has_d_val
!ll&&!rl&&r
14401
MC/DC50%1/2
$has_d_var and $has_d_val
$has_d_var $has_d_val
Truth table66%2/3
A and B
A= $has_d_varB= $has_d_val
ABresult
0X0
100
111
225 1 my $d_new = $d_var->intersect($d_val);
226 1 ▶ return unless $d_new;
Branch: 1 branch
BranchTrueFalseTotal
unless $d_new 0 1 1
227 1 ▶ if ( $d_new->is_bound ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d_new->is_bound) 0 1 1
228 0 my $v = $d_new->bound_value;
229 0 return $subst->bind( $var->id, $v )->bind( $val->id, $v );
230 }
231 1 return $subst->bind( $var->id, $val )->bind( $val->id, $d_new );
232 }
233 elsif ($has_d_var) {
234 0 return $subst->bind( $val->id, $var );
235 }
236 elsif ($has_d_val) {
237 12 return $subst->bind( $var->id, $val );
238 }
239 else {
240 132 return $subst->bind( $var->id, $val );
241 }
242 }
243 elsif ( ref($val) eq 'Logic::Relational::Domain' ) {
244 22 ▶ if ($has_d_var) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_d_var) { } 0 22 22
245 0 my $d_new = $d_var->intersect($val);
246 0 ▶ return unless $d_new;
Branch: 1 branch
BranchTrueFalseTotal
unless $d_new 0 0 0
247 0 ▶ if ( $d_new->is_bound ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d_new->is_bound) 0 0 0
248 0 return $subst->bind( $var->id, $d_new->bound_value );
249 }
250 0 return $subst->bind( $var->id, $d_new );
251 }
252 else {
253 22 ▶ if ( $val->is_bound ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val->is_bound) 0 22 22
254 0 return $subst->bind( $var->id, $val->bound_value );
255 }
256 22 return $subst->bind( $var->id, $val );
257 }
258 }
259 else {
260 960 ▶ if ($has_d_var) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_d_var) { } 119 841 960
261 119 ▶ return unless $val =~ /^-?\d+$/x;
Branch: 1 branch
BranchTrueFalseTotal
unless $val =~ /^-?\d+$/ux 0 119 119
262 119 ▶ return unless $d_var->contains($val);
Branch: 1 branch
BranchTrueFalseTotal
unless $d_var->contains($val) 0 119 119
263 119 return $subst->bind( $var->id, $val );
264 }
265 else {
266 841 return $subst->bind( $var->id, $val );
267 }
268 }
269 }
270  
271 1266 ▶sub occurs_in ( $var_id, $term, $subst ) {
Subroutine occurs_in: called CC=12 SCAR=24.9
Pod documented
272 1266 $term = $subst->walk($term);
273 1266 ▶ if ( ref($term) eq 'Logic::Relational::Variable' ) { ## no critic (ProhibitCascadingIfElse)
Branch: 5 branches
BranchTrueFalseTotal
if (ref $term eq 'Logic::Relational::Variable') { } 169 1097 1266
elsif (ref $term eq 'Logic::Relational::Term') { } 1 1096 1097
elsif (ref $term eq 'ARRAY') { } 77 1019 1096
elsif (ref $term eq 'Logic::Relational::ArrayRest') { } 20 999 1019
elsif (ref $term eq 'HASH') { } 4 995 999
274 169 return $term->id == $var_id;
275 }
276 elsif ( ref($term) eq 'Logic::Relational::Term' ) {
277 1 for my $arg ( @{ $term->args } ) {
278 1 ▶ return 1 if occurs_in( $var_id, $arg, $subst );
Branch: 1 branch
BranchTrueFalseTotal
if occurs_in($var_id, $arg, $subst) 1 0 1
279 }
280 }
281 elsif ( ref($term) eq 'ARRAY' ) {
282 77 for my $arg (@$term) {
283 110 ▶ return 1 if occurs_in( $var_id, $arg, $subst );
Branch: 1 branch
BranchTrueFalseTotal
if occurs_in($var_id, $arg, $subst) 1 109 110
284 }
285 }
286 elsif ( ref($term) eq 'Logic::Relational::ArrayRest' ) {
287 20 return occurs_in( $var_id, $term->term, $subst );
288 }
289 elsif ( ref($term) eq 'HASH' ) {
290 4 for my $val ( values %$term ) {
291 5 ▶ return 1 if occurs_in( $var_id, $val, $subst );
Branch: 1 branch
BranchTrueFalseTotal
if occurs_in($var_id, $val, $subst) 1 4 5
292 }
293 }
294 1074 return 0;
295 }
296  
297 33 1;
« lib/Logic/Relational/Syntax.pm ↑ Summary blib/lib/Logic/Relational/Goal.pm »