POE/Component/Server/Twirc/LogAppender.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 35 CC 2 SCAR 11.5
CC
2
Cov
0%
new
6.0
log
2.0
dump_history
2.0
CRAP 3.1
1 package POE::Component::Server::Twirc::LogAppender;
2 use warnings;
3 use strict;
4  
5 use base qw/Log::Log4perl::Appender/;
6  
7 sub new {
8 my($class, @options) = @_;
9  
10 my $self = {
11 name => 'twirc-logger',
12 irc_channel => '&twirc-log',
13 history => [],
14 history_size => 50,
15 @options,
16 };
17  
18 for ( qw/ircd irc_botname irc_channel/ ) {
19 die "$_ required" unless defined $self->{$_};
20 }
21  
22 bless $self, $class;
23 }
24  
25 sub log {
26 my($self, %params) = @_;
27  
28 $self->{ircd}->yield(daemon_cmd_privmsg =>
29 $self->{irc_botname}, $self->{irc_channel}, $params{message});
30  
31 push @{$self->{history}}, \%params;
32 shift @{$self->{history}} while @{$self->{history}} > $self->{history_size};
33 }
34  
35 sub dump_history {
36 my $self = shift;
37  
38 $self->{ircd}->yield(daemon_cmd_privmsg =>
39 $self->{irc_botname}, $self->{irc_channel}, $_->{message})
40 for @{$self->{history}};
41 }
42  
43 1;