blib/lib/AI/MegaHAL.pm

filter: Statementstmt 69.5% 48 / 69 Branchbran 27.2% 6 / 22 Conditioncond 25.0% 2 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 68.7% 11 / 16 Podpod 75.0% 3 / 4 totaltotal 56.4% 70 / 124 CC 15 SCAR 24.5
CC
15
Cov
57%
AUTOLOAD
34.9
new
10.1
DESTROY
2.0
CRAP 11.5
↑ Summary MegaHAL.xs »
1 package AI::MegaHAL;
2  
3 1 require DynaLoader;
4 1 require Exporter;
5  
6 1 ▶use AutoLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use vars qw(@EXPORT @ISA $VERSION $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 @EXPORT = qw(megahal_setnoprompt
14 megahal_setnowrap
15 megahal_setnobanner
16 megahal_seterrorfile
17 megahal_setstatusfile
18 megahal_initialize
19 megahal_initial_greeting
20 megahal_command
21 megahal_do_reply
22 megahal_learn
23 megahal_output
24 megahal_input
25 megahal_cleanup);
26  
27 1 @ISA = qw(Exporter DynaLoader);
28 1 $VERSION = '0.08_01';
29  
30 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=7 SCAR=35.5
31 # This AUTOLOAD is used to 'autoload' constants from the constant()
32 # XS function. If a constant is not found then control is passed
33 # to the AUTOLOAD in AutoLoader.
34  
35 0 my $constname;
36 0 ($constname = $AUTOLOAD) =~ s/.*:://;
37 0 ▶ croak "& not defined" if $constname eq 'constant';
Branch: 1 branch
BranchTrueFalseTotal
if $constname eq "constant" 0 0 0
38 0 ▶ my $val = constant($constname, @_ ? $_[0] : 0);
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
39 0 ▶ if ($! != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($! != 0) 0 0 0
40 0 ▶ if ($! =~ /Invalid/ || $!{EINVAL}) {
Subroutine BEGIN: called CC=1 SCAR=2.6
Branch: 1 branch
BranchTrueFalseTotal
if ($! =~ /Invalid/ or $!{'EINVAL'}) { } 0 0 0
Condition0%0/3
$! =~ /Invalid/ or $!{"EINVAL"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$! =~ /Invalid/ or $!{"EINVAL"}
$! =~ /Invalid/ $!{"EINVAL"}
Truth table0%0/3
A or B
A= $! =~ /Invalid/B= $!{"EINVAL"}
ABresult
1X1
011
000
41 0 $AutoLoader::AUTOLOAD = $AUTOLOAD;
42 0 goto &AutoLoader::AUTOLOAD;
43 }
44 else {
45 0 croak "Your vendor has not defined AI::MegaHAL macro $constname";
46 }
47 }
48 {
49 0 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.2
50 # Fixed between 5.005_53 and 5.005_61
51 0 ▶ if ($] >= 5.00561) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.00561) { } 0 0 0
52 0 ▶ *$AUTOLOAD = sub () { $val };
Subroutine __ANON__: not called CC=1 SCAR=6.9
53 }
54 else {
55 0 ▶ *$AUTOLOAD = sub { $val };
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 }
57 }
58 0 goto &$AUTOLOAD;
59 }
60  
61 1 ▶sub new {
Subroutine new: called CC=8 SCAR=23.2
Pod undocumented
62 1 my ($class,%args) = @_;
63 1 my $self;
64  
65 # Bless ourselves into the AI::MegaHAL class.
66 1 $self = bless({ },$class);
67  
68 # Make sure that we can find a brain or a training file somewhere
69 # else die with an error.
70 1 ▶ my $path = $args{'Path'} || ".";
Condition50%1/2
$args{'Path'} || '.'
l!l
01
MC/DC0%0/1
$args{'Path'} || '.'
$args{'Path'}
Truth table50%1/2
A
A= $args{'Path'}
Aresult
11
00
71 1 ▶ if(-e "$path/megahal.brn" || -e "$path/megahal.trn") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$path/megahal.brn" or -e "$path/megahal.trn") { } 1 0 1
Condition33%1/3
-e "$path/megahal.brn" or -e "$path/megahal.trn"
l!l&&r!l&&!r
010
MC/DC0%0/2
-e "$path/megahal.brn" or -e "$path/megahal.trn"
-e "$path/megahal.brn" -e "$path/megahal.trn"
Truth table33%1/3
A or B
A= -e "$path/megahal.brn"B= -e "$path/megahal.trn"
ABresult
1X1
011
000
72 1 ▶ chdir($path) || die("Error: chdir: $!\n");
Branch: 1 branch
BranchTrueFalseTotal
chdir $path or die "Error: chdir: $!\n" 1 0 1
73 } else {
74 0 die("Error: unable to locate megahal.brn or megahal.trn\n");
75 }
76  
77 # Set some of the options that may have been passed to us.
78 1 ▶ megahal_setnobanner() if(! $args{'Banner'});
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"Banner"} 1 0 1
79 1 ▶ megahal_setnowrap() if(! $args{'Wrap'});
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"Wrap"} 1 0 1
80 1 ▶ megahal_setnoprompt() if(! $args{'Prompt'});
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"Prompt"} 1 0 1
81  
82 # This flag indicates whether or not we should automatically save
83 # our brain when the object goes out of scope.
84 1 $self->{'AutoSave'} = $args{'AutoSave'};
85  
86 # Initialize ourselves.
87 1 $self->_initialize();
88  
89 1 return $self;
90 }
91  
92 0 ▶sub initial_greeting {
Subroutine initial_greeting: not called CC=1 SCAR=6.9
Pod documented
93 0 my $self = shift;
94  
95 0 return megahal_initial_greeting();
96 }
97  
98 1 ▶sub do_reply {
Subroutine do_reply: called CC=1 SCAR=0.0
Pod documented
99 1 my ($self,$text) = @_;
100  
101 1 return megahal_do_reply($text,0);
102 }
103  
104 0 ▶sub learn {
Subroutine learn: not called CC=1 SCAR=6.9
Pod documented
105 0 my ($self,$text) = @_;
106  
107 0 return megahal_learn($text,0);
108 }
109  
110 1 ▶sub _initialize {
Subroutine _initialize: called CC=1 SCAR=0.0
111 1 my $self = shift;
112  
113 1 megahal_initialize();
114 1 return;
115 }
116  
117 1 ▶sub _cleanup {
Subroutine _cleanup: called CC=1 SCAR=0.0
118 1 my $self = shift;
119  
120 1 megahal_cleanup();
121 1 return;
122 }
123  
124 1 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.1
125 1 my $self = shift;
126  
127 1 ▶ $self->_cleanup() if($self->{'AutoSave'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"AutoSave"} 1 0 1
128 1 return;
129 }
130  
131 1 bootstrap AI::MegaHAL $VERSION;
132 1 1;
133  
134 __END__
↑ Summary MegaHAL.xs »