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

filter: Statementstmt 60.6% 40 / 66 Branchbran 39.5% 19 / 48 Conditioncond 25.0% 15 / 60 MC/DCmcdc 5.5% 2 / 36 Subroutinesub 75.0% 9 / 12 Podpod 50.0% 3 / 6 totaltotal 38.6% 88 / 228 CC 48 SCAR 60.2
CC
48
Cov
43%
_are_identical
588.4
freshen
7.5
is_ground
6.0
CRAP 410.1
↑ Summary blib/lib/Logic/Relational/Goal/Not.pm »
1 package Logic::Relational::Goal::Identical;
2  
3 30 ▶use v5.38;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 ## no critic (Subroutines::ProhibitExcessComplexity)
5 30 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 30 ▶use parent 'Logic::Relational::Goal';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 30 ▶use builtin 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 30 ▶no warnings 'experimental::builtin';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 Logic::Relational::Goal::Identical - Evaluates strict term identity without variable binding.
13  
14 =cut
15  
16 6 ▶sub new ( $class, $left, $right ) {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
17 6 return bless {
18 left => $left,
19 right => $right,
20 }, $class;
21 }
22  
23 0 ▶sub left ($self) { return $self->{left}; }
Subroutine left: not called CC=1 SCAR=6.9
Pod undocumented
24 0 ▶sub right ($self) { return $self->{right}; }
Subroutine right: not called CC=1 SCAR=6.9
Pod undocumented
25  
26 5 ▶sub _are_identical ( $t1, $t2 ) {
Subroutine _are_identical: called CC=41 SCAR=63.8
27 5 ▶ return 1 if !defined($t1) && !defined($t2);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t1 or defined $t2 0 5 5
Condition33%1/3
defined $t1 or defined $t2
l!l&&r!l&&!r
500
MC/DC0%0/2
defined $t1 or defined $t2
defined $t1 defined $t2
Truth table33%1/3
A or B
A= defined $t1B= defined $t2
ABresult
1X1
011
000
28 5 ▶ return 0 if !defined($t1) || !defined($t2);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t1 and defined $t2 0 5 5
Condition33%1/3
defined $t1 and defined $t2
!ll&&!rl&&r
005
MC/DC0%0/2
defined $t1 and defined $t2
defined $t1 defined $t2
Truth table33%1/3
A and B
A= defined $t1B= defined $t2
ABresult
0X0
100
111
29  
30 # Variables: compare ID
31 5 ▶ if ( blessed($t1) && $t1->isa('Logic::Relational::Variable') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($t1) and $t1->isa("Logic::Relational::Variable")) 3 2 5
Condition66%2/3
builtin::blessed($t1) and $t1->isa("Logic::Relational::Variable")
!ll&&!rl&&r
203
MC/DC50%1/2
builtin::blessed($t1) and $t1->isa("Logic::Relational::Variable")
builtin::blessed($t1) $t1->isa("Logic::Relational::Variable")
Truth table66%2/3
A and B
A= builtin::blessed($t1)B= $t1->isa("Logic::Relational::Variable")
ABresult
0X0
100
111
32 3 ▶ return ( blessed($t2)
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($t2) && $t2->isa('Logic::Relational::Variable') && $t1->id eq $t2->id ? : 1 2 3
Condition50%3/6
builtin::blessed($t2) and $t2->isa("Logic::Relational::Variable") and $t1->id eq $t2->id
!ll&&!rl&&r
021
builtin::blessed($t2) and $t2->isa("Logic::Relational::Variable")
!ll&&!rl&&r
003
MC/DC33%1/3
builtin::blessed($t2) and $t2->isa("Logic::Relational::Variable") and $t1->id eq $t2->id
builtin::blessed($t2) $t2->isa("Logic::Relational::Variable") $t1->id eq $t2->id
Truth table50%2/4
A and B and C
A= builtin::blessed($t2)B= $t2->isa("Logic::Relational::Variable")C= $t1->id eq $t2->id
ABCresult
0XX0
10X0
1100
1111
33 && $t2->isa('Logic::Relational::Variable')
34 && $t1->id eq $t2->id ) ? 1 : 0;
35 }
36 2 ▶ if ( blessed($t2) && $t2->isa('Logic::Relational::Variable') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($t2) and $t2->isa("Logic::Relational::Variable")) 0 2 2
Condition33%1/3
builtin::blessed($t2) and $t2->isa("Logic::Relational::Variable")
!ll&&!rl&&r
200
MC/DC0%0/2
builtin::blessed($t2) and $t2->isa("Logic::Relational::Variable")
builtin::blessed($t2) $t2->isa("Logic::Relational::Variable")
Truth table33%1/3
A and B
A= builtin::blessed($t2)B= $t2->isa("Logic::Relational::Variable")
ABresult
0X0
100
111
37 0 return 0;
38 }
39  
40 # Atoms: compare name
41 2 ▶ if ( blessed($t1) && $t1->isa('Logic::Relational::Atom') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($t1) and $t1->isa("Logic::Relational::Atom")) 0 2 2
Condition33%1/3
builtin::blessed($t1) and $t1->isa("Logic::Relational::Atom")
!ll&&!rl&&r
200
MC/DC0%0/2
builtin::blessed($t1) and $t1->isa("Logic::Relational::Atom")
builtin::blessed($t1) $t1->isa("Logic::Relational::Atom")
Truth table33%1/3
A and B
A= builtin::blessed($t1)B= $t1->isa("Logic::Relational::Atom")
ABresult
0X0
100
111
42 0 ▶ return ( blessed($t2)
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($t2) && $t2->isa('Logic::Relational::Atom') && $t1->name eq $t2->name ? : 0 0 0
Condition0%0/6
builtin::blessed($t2) and $t2->isa("Logic::Relational::Atom") and $t1->name eq $t2->name
!ll&&!rl&&r
000
builtin::blessed($t2) and $t2->isa("Logic::Relational::Atom")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($t2) and $t2->isa("Logic::Relational::Atom") and $t1->name eq $t2->name
builtin::blessed($t2) $t2->isa("Logic::Relational::Atom") $t1->name eq $t2->name
Truth table0%0/4
A and B and C
A= builtin::blessed($t2)B= $t2->isa("Logic::Relational::Atom")C= $t1->name eq $t2->name
ABCresult
0XX0
10X0
1100
1111
43 && $t2->isa('Logic::Relational::Atom')
44 && $t1->name eq $t2->name ) ? 1 : 0;
45 }
46 2 ▶ if ( blessed($t2) && $t2->isa('Logic::Relational::Atom') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($t2) and $t2->isa("Logic::Relational::Atom")) 0 2 2
Condition33%1/3
builtin::blessed($t2) and $t2->isa("Logic::Relational::Atom")
!ll&&!rl&&r
200
MC/DC0%0/2
builtin::blessed($t2) and $t2->isa("Logic::Relational::Atom")
builtin::blessed($t2) $t2->isa("Logic::Relational::Atom")
Truth table33%1/3
A and B
A= builtin::blessed($t2)B= $t2->isa("Logic::Relational::Atom")
ABresult
0X0
100
111
47 0 return 0;
48 }
49  
50 # Terms: compare functor and args
51 2 ▶ if ( blessed($t1) && $t1->isa('Logic::Relational::Term') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($t1) and $t1->isa("Logic::Relational::Term")) 0 2 2
Condition33%1/3
builtin::blessed($t1) and $t1->isa("Logic::Relational::Term")
!ll&&!rl&&r
200
MC/DC0%0/2
builtin::blessed($t1) and $t1->isa("Logic::Relational::Term")
builtin::blessed($t1) $t1->isa("Logic::Relational::Term")
Truth table33%1/3
A and B
A= builtin::blessed($t1)B= $t1->isa("Logic::Relational::Term")
ABresult
0X0
100
111
52 return 0
53 unless blessed($t2)
54 && $t2->isa('Logic::Relational::Term')
55 && $t1->functor eq $t2->functor
56 0 ▶ && @{ $t1->args } == @{ $t2->args };
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($t2) and $t2->isa("Logic::Relational::Term") and $t1->functor eq $t2->functor and @{$t1->args;} == @{$t2->args;} 0 0 0
Condition0%0/9
builtin::blessed($t2) and $t2->isa("Logic::Relational::Term") and $t1->functor eq $t2->functor and @{$t1->args;} == @{$t2->args;}
!ll&&!rl&&r
000
builtin::blessed($t2) and $t2->isa("Logic::Relational::Term") and $t1->functor eq $t2->functor
!ll&&!rl&&r
000
builtin::blessed($t2) and $t2->isa("Logic::Relational::Term")
!ll&&!rl&&r
000
MC/DC0%0/4
builtin::blessed($t2) and $t2->isa("Logic::Relational::Term") and $t1->functor eq $t2->functor and @{$t1->args;} == @{$t2->args;}
builtin::blessed($t2) $t2->isa("Logic::Relational::Term") $t1->functor eq $t2->functor @{$t1->args;} == @{$t2->args;}
Truth table0%0/5
A and B and C and D
A= builtin::blessed($t2)B= $t2->isa("Logic::Relational::Term")C= $t1->functor eq $t2->functorD= @{$t1->args;} == @{$t2->args;}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
57  
58 0 for my $i ( 0 .. $#{ $t1->args } ) {
59 0 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
unless _are_identical($t1->args->[$i], $t2->args->[$i]) 0 0 0
60 unless _are_identical( $t1->args->[$i], $t2->args->[$i] );
61 }
62 0 return 1;
63 }
64 2 ▶ if ( blessed($t2) && $t2->isa('Logic::Relational::Term') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($t2) and $t2->isa("Logic::Relational::Term")) 0 2 2
Condition33%1/3
builtin::blessed($t2) and $t2->isa("Logic::Relational::Term")
!ll&&!rl&&r
200
MC/DC0%0/2
builtin::blessed($t2) and $t2->isa("Logic::Relational::Term")
builtin::blessed($t2) $t2->isa("Logic::Relational::Term")
Truth table33%1/3
A and B
A= builtin::blessed($t2)B= $t2->isa("Logic::Relational::Term")
ABresult
0X0
100
111
65 0 return 0;
66 }
67  
68 # Arrays
69 2 ▶ if ( ref($t1) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $t1 eq "ARRAY") 0 2 2
70 0 ▶ return 0 unless ref($t2) eq 'ARRAY' && @$t1 == @$t2;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $t2 eq "ARRAY" and @$t1 == @$t2 0 0 0
Condition0%0/3
ref $t2 eq "ARRAY" and @$t1 == @$t2
!ll&&!rl&&r
000
MC/DC0%0/2
ref $t2 eq "ARRAY" and @$t1 == @$t2
ref $t2 eq "ARRAY" @$t1 == @$t2
Truth table0%0/3
A and B
A= ref $t2 eq "ARRAY"B= @$t1 == @$t2
ABresult
0X0
100
111
71 0 for my $i ( 0 .. $#$t1 ) {
72 0 ▶ return 0 unless _are_identical( $t1->[$i], $t2->[$i] );
Branch: 1 branch
BranchTrueFalseTotal
unless _are_identical($t1->[$i], $t2->[$i]) 0 0 0
73 }
74 0 return 1;
75 }
76  
77 # Hashes
78 2 ▶ if ( ref($t1) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $t1 eq "HASH") 0 2 2
79 0 ▶ return 0 unless ref($t2) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $t2 eq "HASH" 0 0 0
80 0 my @k1 = sort keys %$t1;
81 0 my @k2 = sort keys %$t2;
82 0 ▶ return 0 unless @k1 == @k2;
Branch: 1 branch
BranchTrueFalseTotal
unless @k1 == @k2 0 0 0
83 0 for my $i ( 0 .. $#k1 ) {
84 0 ▶ return 0 unless $k1[$i] eq $k2[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless $k1[$i] eq $k2[$i] 0 0 0
85 return 0
86 0 ▶ unless _are_identical( $t1->{ $k1[$i] }, $t2->{ $k2[$i] } );
Branch: 1 branch
BranchTrueFalseTotal
unless _are_identical($$t1{$k1[$i]}, $$t2{$k2[$i]}) 0 0 0
87 }
88 0 return 1;
89 }
90  
91 # Plain scalar comparison
92 2 ▶ return $t1 eq $t2 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$t1 eq $t2 ? : 1 1 2
93 }
94  
95 5 ▶sub expand ( $self, %args ) {
Subroutine expand: called CC=3 SCAR=11.1
Pod documented
96 5 my $subst = $args{substitution};
97 5 my $remaining = $args{remaining};
98 5 my $state = $args{state};
99  
100 5 my $walked_left = $subst->walk( $self->{left} );
101 5 my $walked_right = $subst->walk( $self->{right} );
102  
103 5 ▶ if ( _are_identical( $walked_left, $walked_right ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_are_identical($walked_left, $walked_right)) 2 3 5
104 2 my $succ = $state->derive( goals => $remaining, );
105 2 ▶ return $succ // ();
Condition33%1/3
$succ // ()
l!l&&r!l&&!r
200
MC/DC0%0/2
$succ // ()
$succ ()
Truth table33%1/3
A // B
A= $succB= ()
ABresult
1X1
011
000
106 }
107 3 return ();
108 }
109  
110 2 ▶sub freshen ( $self, $var_map ) {
Subroutine freshen: called CC=5 SCAR=20.1
Pod documented
111 my $fresh_left =
112 blessed( $self->{left} )
113 && $self->{left}->can('freshen')
114 ? $self->{left}->freshen($var_map)
115 2 ▶ : $self->{left};
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self->{'left'}) && $self->{'left'}->can('freshen') ? : 2 0 2
Condition33%1/3
builtin::blessed($self->{"left"}) and $self->{"left"}->can("freshen")
!ll&&!rl&&r
002
MC/DC0%0/2
builtin::blessed($self->{"left"}) and $self->{"left"}->can("freshen")
builtin::blessed($self->{"left"}) $self->{"left"}->can("freshen")
Truth table33%1/3
A and B
A= builtin::blessed($self->{"left"})B= $self->{"left"}->can("freshen")
ABresult
0X0
100
111
116  
117 my $fresh_right =
118 blessed( $self->{right} )
119 && $self->{right}->can('freshen')
120 ? $self->{right}->freshen($var_map)
121 2 ▶ : $self->{right};
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self->{'right'}) && $self->{'right'}->can('freshen') ? : 2 0 2
Condition33%1/3
builtin::blessed($self->{"right"}) and $self->{"right"}->can("freshen")
!ll&&!rl&&r
002
MC/DC0%0/2
builtin::blessed($self->{"right"}) and $self->{"right"}->can("freshen")
builtin::blessed($self->{"right"}) $self->{"right"}->can("freshen")
Truth table33%1/3
A and B
A= builtin::blessed($self->{"right"})B= $self->{"right"}->can("freshen")
ABresult
0X0
100
111
122  
123 2 return ref($self)->new( $fresh_left, $fresh_right );
124 }
125  
126 0 ▶sub is_ground ( $self, $subst ) {
Subroutine is_ground: not called CC=2 SCAR=17.9
Pod documented
127 return $self->term_is_ground( $self->{left}, $subst )
128 0 ▶ && $self->term_is_ground( $self->{right}, $subst );
Condition0%0/3
$self->term_is_ground($self->{'left'}, $subst) && $self->term_is_ground($self->{'right'}, $subst)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->term_is_ground($self->{'left'}, $subst) && $self->term_is_ground($self->{'right'}, $subst)
$self->term_is_ground($self->{'left'}, $subst) $self->term_is_ground($self->{'right'}, $subst)
Truth table0%0/3
A && B
A= $self->term_is_ground($self->{'left'}, $subst)B= $self->term_is_ground($self->{'right'}, $subst)
ABresult
0X0
100
111
129 }
130  
131 30 1;
↑ Summary blib/lib/Logic/Relational/Goal/Not.pm »