File Coverage

blib/lib/POE/Component/Server/Twirc/LogAppender.pm
Criterion Covered Total %
statement 9 24 37.5
branch 0 2 0.0
condition n/a
subroutine 3 6 50.0
pod 1 3 33.3
total 13 35 37.1


line stmt bran cond sub pod time code
1             package POE::Component::Server::Twirc::LogAppender;
2              
3 2     2   8 use warnings;
  2         3  
  2         47  
4 2     2   7 use strict;
  2         2  
  2         42  
5              
6 2     2   6 use base qw/Log::Log4perl::Appender/;
  2         3  
  2         450  
7              
8             sub new {
9 0     0 1   my($class, @options) = @_;
10              
11 0           my $self = {
12             name => 'twirc-logger',
13             irc_channel => '&twirc-log',
14             history => [],
15             history_size => 50,
16             @options,
17             };
18              
19 0           for ( qw/ircd irc_botname irc_channel/ ) {
20 0 0         die "$_ required" unless defined $self->{$_};
21             }
22              
23 0           bless $self, $class;
24             }
25              
26             sub log {
27 0     0 0   my($self, %params) = @_;
28              
29 0           $self->{ircd}->yield(daemon_cmd_privmsg =>
30             $self->{irc_botname}, $self->{irc_channel}, $params{message});
31              
32 0           push @{$self->{history}}, \%params;
  0            
33 0           shift @{$self->{history}} while @{$self->{history}} > $self->{history_size};
  0            
  0            
34             }
35              
36             sub dump_history {
37 0     0 0   my $self = shift;
38              
39 0           $self->{ircd}->yield(daemon_cmd_privmsg =>
40             $self->{irc_botname}, $self->{irc_channel}, $_->{message})
41 0           for @{$self->{history}};
42             }
43              
44             1;