-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtrain.pl
60 lines (50 loc) · 1.24 KB
/
train.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use strict;
use warnings;
use POE qw[Component::Hailo Wheel::ReadWrite];
POE::Session->create(
package_states => [
(__PACKAGE__) => [ qw(_start hailo_learned hailo_replied _input _error) ],
],
);
POE::Kernel->run;
exit 0;
sub _start {
my ($kernel,$heap) = @_[KERNEL,HEAP];
POE::Component::Hailo->spawn(
alias => 'hailo',
Hailo_args => {
storage_class => 'SQLite',
brain_resource => 'hailo.sqlite',
},
);
$heap->{stdin} = POE::Wheel::ReadWrite->new(
Handle => \*STDIN,
InputEvent => '_input',
ErrorEvent => '_error',
);
return;
}
sub _error {
my ($operation, $errnum, $errstr, $id) = @_[ARG0..ARG3];
warn "Wheel $id encountered $operation error $errnum: $errstr\n";
delete $_[HEAP]{stdin}; # shut down that wheel
POE::Kernel->post(hailo => reply => ['This']);
return;
}
sub _input {
my ($heap,$input) = @_[HEAP,ARG0];
return if $input =~ m!^#!;
$poe_kernel->post( 'hailo', 'learn', [$input] );
return;
}
sub hailo_learned {
print "Hailo learned shit\n";
return;
}
sub hailo_replied {
my $reply = $_[ARG0]->[0];
die "Didn't get a reply" if !defined $reply;
print "Got reply: $reply\n";
POE::Kernel->post(hailo => 'shutdown');
return;
}