Prolog.pm

filter: Statementstmt 71.8% 51 / 71 Branchbran 33.3% 6 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 72.2% 13 / 18 Podpod 88.8% 8 / 9 totaltotal 67.2% 78 / 116 CC 10 SCAR 11.8
CC
10
Cov
64%
do
6.0
trace
6.0
quote
6.0
CRAP 3.2
« Prolog/Parser/PreProcessor/Math.pm ↑ Summary Prolog/TermList.pm »
1 package AI::Prolog;
2 5 $VERSION = '0.741'; ## no critic
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Carp qw( confess carp croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use Hash::Util 'lock_keys';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Exporter::Tidy shortcuts => [qw/Parser Term Engine/];
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 ▶use aliased 'AI::Prolog::Parser';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use aliased 'AI::Prolog::Term';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use aliased 'AI::Prolog::Engine';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 ▶use Text::Quote;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Regexp::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # they don't want pretty printed strings if they're using this interface
17 5 Engine->formatted(0);
18  
19 # Until (and unless) we figure out the weird bug that prevents some values
20 # binding in the external interface, we need to stick with this as the default
21 5 Engine->raw_results(1);
22  
23 7 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
24 7 my ( $class, $program ) = @_;
25 7 my $self = bless {
26 _prog => Parser->consult($program),
27 _query => undef,
28 _engine => undef,
29 } => $class;
30 7 lock_keys %$self;
31 7 return $self;
32 }
33  
34 0 ▶sub do {
Subroutine do: not called CC=2 SCAR=17.9
Pod documented
35 0 my ( $self, $query ) = @_;
36 0 $self->query($query);
37 0 ▶ 1 while $self->results;
Branch: 1 branch
BranchTrueFalseTotal
$self->results and do { '???' } 0 0 0
38 0 $self;
39 }
40  
41 37 ▶sub query {
Subroutine query: called CC=3 SCAR=11.0
Pod documented
42 37 my ( $self, $query ) = @_;
43  
44 # make that final period optional
45 37 ▶ $query .= '.' unless $query =~ /\.$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $query =~ /\.$/ 31 6 37
46 37 $self->{_query} = Term->new($query);
47 37 ▶ unless ( defined $self->{_engine} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_engine"}) 7 30 37
48  
49 # prime the pump
50 7 $self->{_engine} = Engine->new( @{$self}{qw/_query _prog/} );
51 }
52 37 $self->{_engine}->query( $self->{_query} );
53 37 return $self;
54 }
55  
56 44 ▶sub results {
Subroutine results: called CC=2 SCAR=7.6
Pod documented
57 44 my $self = shift;
58 44 ▶ unless ( defined $self->{_query} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_query"}) 0 44 44
59 0 croak "You can't fetch results because you have not set a query";
60 }
61 44 $self->{_engine}->results;
62 }
63  
64 0 ▶sub trace {
Subroutine trace: not called CC=2 SCAR=17.9
Pod documented
65 0 my $self = shift;
66 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
67 0 $self->{_engine}->trace(shift);
68 0 return $self;
69 }
70 0 return $self->{_engine}->trace;
71 }
72  
73 1 ▶sub raw_results {
Subroutine raw_results: called CC=2 SCAR=7.4
Pod documented
74 1 my $class = shift;
75 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 0 1
76 1 Engine->raw_results(shift);
77 1 return $class;
78 }
79 0 return Engine->raw_results;
80 }
81  
82 5 my $QUOTER;
83  
84 0 ▶sub quote {
Subroutine quote: not called CC=2 SCAR=17.9
Pod documented
85 0 my ( $proto, $string ) = @_;
86 0 ▶ $QUOTER = Text::Quote->new unless $QUOTER;
Branch: 1 branch
BranchTrueFalseTotal
unless $QUOTER 0 0 0
87 0 return $QUOTER->quote_simple($string);
88 }
89  
90 0 ▶sub list {
Subroutine list: not called CC=2 SCAR=17.9
Pod documented
91 0 my $proto = shift;
92 return
93 0 ▶ join ", " => map { /^$RE{num}{real}$/ ? $_ : $proto->quote($_) } @_;
Branch: 1 branch
BranchTrueFalseTotal
/^$AI::Prolog::RE{'num'}{'real'}$/ ? : 0 0 0
94 }
95  
96 0 ▶sub continue {
Subroutine continue: not called CC=2 SCAR=17.9
Pod undocumented
97 0 my $self = shift;
98 0 ▶ return 1 unless $self->{_engine}; # we haven't started yet!
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_engine"} 0 0 0
99 0 !$self->{_engine}->halt;
100 }
101  
102 5 1;
103  
104 __END__
« Prolog/Parser/PreProcessor/Math.pm ↑ Summary Prolog/TermList.pm »