| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package AI::MegaHAL; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require DynaLoader; |
|
4
|
|
|
|
|
|
|
require Exporter; |
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3839
|
use AutoLoader; |
|
|
1
|
|
|
|
|
953
|
|
|
|
1
|
|
|
|
|
5
|
|
|
7
|
1
|
|
|
1
|
|
26
|
use Carp; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
48
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
2
|
use vars qw(@EXPORT @ISA $VERSION $AUTOLOAD); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
132
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
@ISA = qw(Exporter DynaLoader); |
|
28
|
|
|
|
|
|
|
$VERSION = '0.08'; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub AUTOLOAD { |
|
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
|
|
|
0
|
|
0
|
my $constname; |
|
36
|
0
|
|
|
|
|
0
|
($constname = $AUTOLOAD) =~ s/.*:://; |
|
37
|
0
|
0
|
|
|
|
0
|
croak "& not defined" if $constname eq 'constant'; |
|
38
|
0
|
0
|
|
|
|
0
|
my $val = constant($constname, @_ ? $_[0] : 0); |
|
39
|
0
|
0
|
|
|
|
0
|
if ($! != 0) { |
|
40
|
1
|
0
|
0
|
1
|
|
386
|
if ($! =~ /Invalid/ || $!{EINVAL}) { |
|
|
1
|
|
|
|
|
838
|
|
|
|
1
|
|
|
|
|
48
|
|
|
|
0
|
|
|
|
|
0
|
|
|
41
|
0
|
|
|
|
|
0
|
$AutoLoader::AUTOLOAD = $AUTOLOAD; |
|
42
|
0
|
|
|
|
|
0
|
goto &AutoLoader::AUTOLOAD; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
else { |
|
45
|
0
|
|
|
|
|
0
|
croak "Your vendor has not defined AI::MegaHAL macro $constname"; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
{ |
|
49
|
1
|
|
|
1
|
|
4
|
no strict 'refs'; |
|
|
1
|
|
|
|
|
0
|
|
|
|
1
|
|
|
|
|
542
|
|
|
|
0
|
|
|
|
|
0
|
|
|
50
|
|
|
|
|
|
|
# Fixed between 5.005_53 and 5.005_61 |
|
51
|
0
|
0
|
|
|
|
0
|
if ($] >= 5.00561) { |
|
52
|
0
|
|
|
0
|
|
0
|
*$AUTOLOAD = sub () { $val }; |
|
|
0
|
|
|
|
|
0
|
|
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
else { |
|
55
|
0
|
|
|
0
|
|
0
|
*$AUTOLOAD = sub { $val }; |
|
|
0
|
|
|
|
|
0
|
|
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
0
|
|
|
|
|
0
|
goto &$AUTOLOAD; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub new { |
|
62
|
1
|
|
|
1
|
0
|
78
|
my ($class,%args) = @_; |
|
63
|
1
|
|
|
|
|
1
|
my $self; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Bless ourselves into the AI::MegaHAL class. |
|
66
|
1
|
|
|
|
|
3
|
$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
|
|
50
|
|
|
6
|
my $path = $args{'Path'} || "."; |
|
71
|
1
|
50
|
33
|
|
|
20
|
if(-e "$path/megahal.brn" || -e "$path/megahal.trn") { |
|
72
|
1
|
50
|
|
|
|
17
|
chdir($path) || die("Error: chdir: $!\n"); |
|
73
|
|
|
|
|
|
|
} else { |
|
74
|
0
|
|
|
|
|
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
|
50
|
|
|
|
6
|
megahal_setnobanner() if(! $args{'Banner'}); |
|
79
|
1
|
50
|
|
|
|
4
|
megahal_setnowrap() if(! $args{'Wrap'}); |
|
80
|
1
|
50
|
|
|
|
6
|
megahal_setnoprompt() if(! $args{'Prompt'}); |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# This flag indicates whether or not we should automatically save |
|
83
|
|
|
|
|
|
|
# our brain when the object goes out of scope. |
|
84
|
1
|
|
|
|
|
9
|
$self->{'AutoSave'} = $args{'AutoSave'}; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# Initialize ourselves. |
|
87
|
1
|
|
|
|
|
5
|
$self->_initialize(); |
|
88
|
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
11
|
return $self; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub initial_greeting { |
|
93
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
0
|
return megahal_initial_greeting(); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub do_reply { |
|
99
|
1
|
|
|
1
|
1
|
145
|
my ($self,$text) = @_; |
|
100
|
|
|
|
|
|
|
|
|
101
|
1
|
|
|
|
|
715927
|
return megahal_do_reply($text,0); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub learn { |
|
105
|
0
|
|
|
0
|
1
|
0
|
my ($self,$text) = @_; |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
0
|
return megahal_learn($text,0); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub _initialize { |
|
111
|
1
|
|
|
1
|
|
1
|
my $self = shift; |
|
112
|
|
|
|
|
|
|
|
|
113
|
1
|
|
|
|
|
11331
|
megahal_initialize(); |
|
114
|
1
|
|
|
|
|
8
|
return; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub _cleanup { |
|
118
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
|
119
|
|
|
|
|
|
|
|
|
120
|
1
|
|
|
|
|
7129
|
megahal_cleanup(); |
|
121
|
1
|
|
|
|
|
10
|
return; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub DESTROY { |
|
125
|
1
|
|
|
1
|
|
118
|
my $self = shift; |
|
126
|
|
|
|
|
|
|
|
|
127
|
1
|
50
|
|
|
|
9
|
$self->_cleanup() if($self->{'AutoSave'}); |
|
128
|
1
|
|
|
|
|
17
|
return; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
bootstrap AI::MegaHAL $VERSION; |
|
132
|
|
|
|
|
|
|
1; |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |