blib/lib/Morris/Plugin/Oper.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 57 CC 3 SCAR 20.8
CC
3
Cov
0%
handle_message
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 8.0
1 package Morris::Plugin::Oper;
2 use Moose;
3 use namespace::clean -except => qw(meta);
4  
5 # TODO: for jshirley
6 #
7 # <Connection whatever>
8 # <Plugin DBI>
9 # <Instance main>
10 # dsn dbi:mysql:dbname=whatever
11 # </Instance>
12 # </Plugin>
13 # <Plugin Oper::DBI>
14 # dbname main
15 # </Plugin>
16 # </Connection>
17 #
18 # =head1 DESCRIPTION
19 #
20 # See Morris::Plugin::Oper::DBI for ways to keep this data in a database
21  
22 extends 'Morris::Plugin';
23  
24 has channels => (
25 is => 'ro',
26 isa => 'HashRef[HashRef[ArrayRef]]',
27 required => 1,
28 );
29  
30 override new_from_config => sub {
31 my ($class, $args) = @_;
32  
33 my $channels = delete $args->{channel};
34 if ($channels) {
35 if (ref $channels ne 'HASH') {
36 confess "Oper -> Channel must be a hash";
37 }
38  
39 while (my ($channel, $config) = each %$channels) {
40 if (ref $config->{op} ne 'ARRAY') {
41 $config->{op} = [ $config->{op} ];
42 }
43 }
44  
45 $args->{channels} = $channels;
46 }
47 $class->new(%$args);
48 };
49  
50 after register => sub {
51 my ($self, $conn) = @_;
52 $conn->register_hook( 'channel.joined', sub {
53 $self->handle_message(@_);
54 });
55 };
56  
57 sub handle_message {
58 my ($self, $channel, $address) = @_;
59  
60 my $config = $self->channels->{ $channel } ||
61 $self->channels->{ '*' };
62 if (! $config) {
63 return;
64 }
65  
66 my $id = ${ $address->str_ref };
67 if ( grep { $id =~ /$_/ } @{ $config->{op} } ) {
68 $self->connection->irc_mode({
69 channel => $channel,
70 mode => '+o',
71 who => $address->nickname,
72 });
73 }
74 }
75  
76 __PACKAGE__->meta->make_immutable();
77  
78 1;
79  
80 __END__