Amethyst/Message.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 87 CC 7 SCAR 17.0
CC
7
Cov
0%
new
12.0
AUTOLOAD
12.0
action
6.0
CRAP 5.5
1 package Amethyst::Message;
2  
3 use strict;
4 use vars qw(@ISA @EXPORT $AUTOLOAD %VALID);
5 use Carp;
6 use Exporter;
7 use POE;
8 use Amethyst;
9  
10 @ISA = qw(Exporter);
11 @EXPORT = qw(ACT_SAY ACT_EMOTE CHAN_PRIVATE);
12 %VALID = map { $_ => 1 } qw(
13 connection class
14 channel user action
15 content
16 );
17  
18 sub ACT_SAY () { 0; }
19 sub ACT_EMOTE () { 1; }
20  
21 sub CHAN_PRIVATE () { '_tell' }
22  
23 sub DESTROY { } # Don't autoload
24  
25 sub new {
26 my $class = shift;
27 my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ };
28 $self->{Hints} = { } unless exists $self->{Hints};
29 return bless $self, $class;
30 }
31  
32 sub AUTOLOAD {
33 my $func = $AUTOLOAD;
34 $func =~ s/.*:://;
35 if ($VALID{$func}) {
36 my $key = ucfirst $func;
37 eval qq {
38 sub $func {
39 my \$self = shift;
40 \$self->{$key} = \$_[0] if defined \$_[0];
41 return \$self->{$key};
42 }
43 };
44 die $@ if $@;
45 goto &$AUTOLOAD;
46 }
47 croak "Could not autoload $AUTOLOAD ($func)";
48 }
49  
50 sub action {
51 my $self = shift;
52 $self->{Action} = $_[0] if defined $_[0];
53 return $self->{Action};
54 }
55  
56 sub hint {
57 my $self = shift;
58 $self->{Hints}->{$_[0]} = $_[1] if defined $_[1];
59 return $self->{Hints}->{$_[0]};
60 }
61  
62 sub send {
63 my $self = shift;
64 # print STDERR "Sending message to $self->{Connection}\n";
65 $poe_kernel->post($self->{Connection}, 'send', $self);
66 }
67  
68 sub reply {
69 my $self = shift;
70 my $content = shift;
71  
72 return new Amethyst::Message(
73 Connection => $self->{Connection},
74 Channel => $self->{Channel},
75 User => $self->{User},
76 Action => ACT_SAY,
77 Content => $content,
78 );
79 }
80  
81 1;