Amethyst/Brain/Infobot/Module/Excuse.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 46 CC 2 SCAR 10.6
CC
2
Cov
0%
excuse
6.0
new
2.0
action
2.0
CRAP 2.9
1 package Amethyst::Brain::Infobot::Module::Excuse;
2  
3 use strict;
4 use vars qw(@ISA);
5 use Socket qw(AF_INET SOCK_STREAM);
6 use POE qw(Wheel::SocketFactory Wheel::ReadWrite
7 Filter::Line Driver::SysRW);
8 use Amethyst::Brain::Infobot::Module;
9  
10 @ISA = qw(Amethyst::Brain::Infobot::Module);
11  
12 sub new {
13 my $class = shift;
14  
15 my $self = $class->SUPER::new(
16 Name => 'Excuse',
17 Regex => qr/^(give me an? )?excuse$/i,
18 Usage => '((?:give me an)? excuse)',
19 Description => "Get an excuse from the excuse " .
20 "server.",
21 @_
22 );
23  
24 return bless $self, $class;
25 }
26  
27 sub action {
28 my ($self, $message) = @_;
29  
30 my $reply = $self->reply_to($message, $self->excuse());
31 $reply->send;
32  
33 return 1;
34 }
35  
36 sub excuse {
37 my $self = shift;
38  
39 unless ($self->{excuses}) {
40 while (<DATA>) {
41 chomp;
42 push @{$self->{excuses}}, $_;
43 }
44 }
45  
46 my $e = $self->{excuses}->[rand(@{$self->{excuses}})];
47  
48 return $e;
49 }
50  
51  
52  
53  
54  
55 #sub action {
56 # my ($self, $message) = @_;
57 #
58 # my %states = map { $_ => "handler_$_" } qw(
59 # _start connect failure read
60 # );
61 #
62 # print STDERR "Creating child session for excuse\n";
63 #
64 # POE::Session->create(
65 # package_states => [ ref($self) => \%states ],
66 # args => [ $self, $message ],
67 # );
68 #
69 # return 1;
70 #}
71 #
72 #sub handler_read {
73 # my ($kernel, $heap, $session, $data) =
74 # @_[KERNEL, HEAP, SESSION, ARG0];
75 # $data =~ s/Your excuse is: // or return undef;
76 # chomp($data);
77 #
78 # my $reply = $heap->{Module}->reply_to($heap->{Message}, $data);
79 # $reply->send;
80 #
81 # delete $heap->{ReadWrite};
82 #}
83 #
84 #sub handler_connect {
85 # my ($kernel, $heap, $session, $socket) =
86 # @_[KERNEL, HEAP, SESSION, ARG0];
87 #
88 # delete $heap->{SocketFactory};
89 #
90 # my $wheel = POE::Wheel::ReadWrite->new(
91 # Handle => $socket,
92 # Driver => POE::Driver::SysRW->new(),
93 # Filter => POE::Filter::Line->new(),
94 # InputEvent => 'read',
95 # );
96 #
97 # $heap->{ReadWrite} = $wheel;
98 #}
99 #
100 #sub handler_failure {
101 # my ($kernel, $heap, $session, $reason) =
102 # @_[KERNEL, HEAP, SESSION, ARG0, ARG2];
103 #
104 # my $reply = $heap->{Module}->reply_to($heap->{Message},
105 # "Excuse failure: $reason");
106 # $reply->send;
107 #}
108 #
109 #sub handler__start {
110 # my ($kernel, $heap, $session, $module, $message) =
111 # @_[KERNEL, HEAP, SESSION, ARG0, ARG1];
112 #
113 # $heap->{Module} = $module;
114 # $heap->{Message} = $message;
115 #
116 # my $wheel = new POE::Wheel::SocketFactory(
117 # SocketDomain => AF_INET,
118 # SocketType => SOCK_STREAM,
119 # SocketProtocol => 'tcp',
120 # RemoteAddress => 'bofh.engr.wisc.edu',
121 # RemotePort => 666,
122 # SuccessEvent => 'connect',
123 # FailureEvent => 'failure',
124 # );
125 #
126 # $heap->{SocketFactory} = $wheel;
127 #}
128  
129 1;
130  
131 __DATA__