lib/Logic/Relational/Clause.pm

filter: Statementstmt 100% 24 / 24 Branchbran 100% 2 / 2 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 6 / 6 totaltotal 95.7% 45 / 47 CC 4 SCAR 6.9
CC
4
Cov
97%
new
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« blib/lib/Logic/Relational/Term.pm ↑ Summary lib/Logic/Relational/TraceEvent.pm »
1 package Logic::Relational::Clause;
2  
3 26 ▶use v5.38;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 26 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Logic::Relational::Clause - Represents a logic clause (fact or rule).
9  
10 =head1 SYNOPSIS
11  
12 use Logic::Relational::Clause;
13 my $clause = Logic::Relational::Clause->new(
14 head => $head_term,
15 body => $body_goal,
16 );
17  
18 =head1 DESCRIPTION
19  
20 C<Logic::Relational::Clause> represents a logical clause. A fact is a clause
21 with no body goals (or rather, the body defaults to C<True>). A rule contains
22 a body C<Goal> that must be satisfied for the clause head to hold.
23  
24 =head1 METHODS
25  
26 =head2 new
27  
28 Constructor. Takes C<head> (Term), C<body> (Goal, optional), C<id> (string, optional),
29 and C<metadata> (hashref, optional).
30  
31 =head2 id
32  
33 Returns the unique ID of the clause (e.g. C<clause-1>).
34  
35 =head2 head
36  
37 Returns the head term of the clause.
38  
39 =head2 body
40  
41 Returns the body goal of the clause.
42  
43 =head2 metadata
44  
45 Returns the metadata associated with the clause.
46  
47 =head2 freshen
48  
49 Returns a fresh copy of the clause where all its logical variables are mapped
50 to newly generated variables, preserving variable sharing within the clause.
51  
52 =cut
53  
54 26 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 1362 ▶sub new ( $class, %args ) {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
57 1362 ▶ my $head = $args{head} // croak "head term is required";
Condition50%1/2
$args{"head"} // croak("head term is required")
l!l
13620
MC/DC0%0/1
$args{"head"} // croak("head term is required")
$args{"head"}
Truth table50%1/2
A
A= $args{"head"}
Aresult
11
00
58  
59 # We will import True goal dynamically or assume it is loaded to avoid circular dependency
60 1362 my $body = $args{body};
61 1362 ▶ if ( !$body ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($body) 291 1071 1362
62 291 require Logic::Relational::Goal::True;
63 291 $body = Logic::Relational::Goal::True->new;
64 }
65 my $self = {
66 id => $args{id},
67 head => $head,
68 body => $body,
69 metadata => $args{metadata} // {},
70 1362 ▶ };
Condition100%2/2
$args{"metadata"} // {}
l!l
1108254
MC/DC100%1/1
$args{"metadata"} // {}
$args{"metadata"}
Truth table100%2/2
A
A= $args{"metadata"}
Aresult
11
00
71 1362 return bless $self, $class;
72 }
73  
74 681 ▶sub id ($self) {
Subroutine id: called CC=1 SCAR=0.0
Pod documented
75 681 return $self->{id};
76 }
77  
78 2058 ▶sub head ($self) {
Subroutine head: called CC=1 SCAR=0.0
Pod documented
79 2058 return $self->{head};
80 }
81  
82 445 ▶sub body ($self) {
Subroutine body: called CC=1 SCAR=0.0
Pod documented
83 445 return $self->{body};
84 }
85  
86 2000 ▶sub metadata ($self) {
Subroutine metadata: called CC=1 SCAR=0.0
Pod documented
87 2000 return $self->{metadata};
88 }
89  
90 714 ▶sub freshen ($self) {
Subroutine freshen: called CC=1 SCAR=0.0
Pod documented
91 714 my $var_map = {};
92 714 my $fresh_head = $self->{head}->freshen($var_map);
93 714 my $fresh_body = $self->{body}->freshen($var_map);
94 return ref($self)->new(
95 id => $self->{id},
96 head => $fresh_head,
97 body => $fresh_body,
98 metadata => $self->{metadata},
99 714 );
100 }
101  
102 26 1;
« blib/lib/Logic/Relational/Term.pm ↑ Summary lib/Logic/Relational/TraceEvent.pm »