blib/lib/Logic/Relational/Goal.pm

filter: Statementstmt 44.8% 13 / 29 Branchbran 33.3% 6 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 4 / 8 Podpod 80.0% 4 / 5 totaltotal 45.0% 27 / 60 CC 13 SCAR 34.4
CC
13
Cov
40%
term_is_ground
50.3
as_string
6.0
expand
2.0
CRAP 31.2
« blib/lib/Logic/Relational/Unifier.pm ↑ Summary lib/Logic/Relational/Program.pm »
1 package Logic::Relational::Goal;
2  
3 31 ▶use v5.38;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 31 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Logic::Relational::Goal - Base class for relational logic goals.
9  
10 =head1 SYNOPSIS
11  
12 package Logic::Relational::Goal::MyGoal;
13 use parent 'Logic::Relational::Goal';
14  
15 =head1 DESCRIPTION
16  
17 C<Logic::Relational::Goal> defines the interface for all logic goals in the engine.
18 Every goal must implement C<expand> and C<freshen>.
19  
20 =head1 METHODS
21  
22 =head2 expand
23  
24 Abstract method. Evaluates the goal and returns a list of successor C<Logic::Relational::State> objects.
25  
26 =head2 freshen
27  
28 Abstract method. Takes a variable mapping and returns a freshened copy of the goal.
29  
30 =head2 is_ground
31  
32 Abstract method. Checks if the goal is ground (contains no unbound variables)
33 under the current substitution.
34  
35 =head2 term_is_ground
36  
37 Helper method to check if a term is ground under a substitution.
38  
39 =cut
40  
41 31 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 0 ▶sub expand ( $self, %args ) {
Subroutine expand: not called CC=1 SCAR=6.9
Pod documented
44 0 croak "expand method must be implemented by subclass";
45 }
46  
47 0 ▶sub freshen ( $self, $var_map ) {
Subroutine freshen: not called CC=1 SCAR=6.9
Pod documented
48 0 croak "freshen method must be implemented by subclass";
49 }
50  
51 0 ▶sub is_ground ( $self, $subst ) {
Subroutine is_ground: not called CC=1 SCAR=6.9
Pod documented
52 0 croak "is_ground method must be implemented by subclass";
53 }
54  
55 40 ▶sub term_is_ground ( $self, $term, $subst ) {
Subroutine term_is_ground: called CC=12 SCAR=39.2
Pod documented
56 40 $term = $subst->walk($term);
57 40 ▶ if ( ref($term) eq 'Logic::Relational::Variable' ) { ## no critic (ProhibitCascadingIfElse)
Branch: 5 branches
BranchTrueFalseTotal
if (ref $term eq 'Logic::Relational::Variable') { } 1 39 40
elsif (ref $term eq 'Logic::Relational::Term') { } 0 39 39
elsif (ref $term eq 'ARRAY') { } 0 39 39
elsif (ref $term eq 'Logic::Relational::ArrayRest') { } 0 39 39
elsif (ref $term eq 'HASH') { } 0 39 39
58 1 return 0;
59 }
60 elsif ( ref($term) eq 'Logic::Relational::Term' ) {
61 0 for my $arg ( @{ $term->args } ) {
62 0 ▶ return 0 unless $self->term_is_ground( $arg, $subst );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->term_is_ground($arg, $subst) 0 0 0
63 }
64 }
65 elsif ( ref($term) eq 'ARRAY' ) {
66 0 for my $arg (@$term) {
67 0 ▶ return 0 unless $self->term_is_ground( $arg, $subst );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->term_is_ground($arg, $subst) 0 0 0
68 }
69 }
70 elsif ( ref($term) eq 'Logic::Relational::ArrayRest' ) {
71 0 return $self->term_is_ground( $term->term, $subst );
72 }
73 elsif ( ref($term) eq 'HASH' ) {
74 0 for my $val ( values %$term ) {
75 0 ▶ return 0 unless $self->term_is_ground( $val, $subst );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->term_is_ground($val, $subst) 0 0 0
76 }
77 }
78 39 return 1;
79 }
80  
81 0 ▶sub as_string ($self) {
Subroutine as_string: not called CC=2 SCAR=17.9
Pod undocumented
82 0 ▶ if ( $self->can('as_term') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("as_term")) 0 0 0
83 0 return $self->as_term->as_string;
84 }
85 0 my $pkg = ref($self);
86 0 $pkg =~ s/^Logic::Relational::Goal:://x;
87 0 return $pkg;
88 }
89  
90 31 1;
« blib/lib/Logic/Relational/Unifier.pm ↑ Summary lib/Logic/Relational/Program.pm »