blib/lib/AI/MegaHAL.pm

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