File Coverage

blib/lib/POE/Component/IRC/Plugin/MultiProxy/Away.pm
Criterion Covered Total %
statement 11 48 22.9
branch 0 14 0.0
condition 0 3 0.0
subroutine 5 12 41.6
pod 2 7 28.5
total 18 84 21.4


line stmt bran cond sub pod time code
1             package POE::Component::IRC::Plugin::MultiProxy::Away;
2             BEGIN {
3 1     1   1136 $POE::Component::IRC::Plugin::MultiProxy::Away::AUTHORITY = 'cpan:HINRIK';
4             }
5             BEGIN {
6 1     1   20 $POE::Component::IRC::Plugin::MultiProxy::Away::VERSION = '0.01';
7             }
8              
9 1     1   10 use strict;
  1         2  
  1         43  
10 1     1   6 use warnings FATAL => 'all';
  1         14  
  1         54  
11 1     1   1045 use POE::Component::IRC::Plugin qw( :ALL );
  1         460  
  1         763  
12              
13             sub new {
14 0     0 1   my ($package, %self) = @_;
15 0           return bless \%self, $package;
16             }
17              
18             sub PCI_register {
19 0     0 0   my ($self, $irc) = @_;
20              
21 0 0         if (!$irc->isa('POE::Component::IRC::State')) {
22 0           die __PACKAGE__ . " requires PoCo::IRC::State or a subclass thereof\n";
23             }
24              
25 0 0         $self->{Message} = 'No clients attached' unless defined $self->{Message};
26 0           $self->{clients} = 0;
27              
28 0 0 0       if ($irc->connected() && $irc->is_away($irc->nick_name())) {
29 0           $self->{away} = 1;
30             }
31              
32 0           $irc->plugin_register($self, 'SERVER', qw(001 proxy_authed proxy_close));
33 0           return 1;
34             }
35              
36             sub PCI_unregister {
37 0     0 0   return 1;
38             }
39              
40             sub S_001 {
41 0     0 0   my ($self, $irc) = splice @_, 0, 2;
42 0 0         if (!$self->{clients}) {
43 0           $irc->yield(away => $self->{Message});
44 0           $self->{away} = 1;
45             }
46 0           return PCI_EAT_NONE;
47             }
48              
49             sub S_proxy_authed {
50 0     0 0   my ($self, $irc) = splice @_, 0, 2;
51 0           my $client = ${ $_[0] };
  0            
52 0           $self->{clients}++;
53 0 0         if ($self->{away}) {
54 0           $irc->yield('away');
55 0           $self->{away} = 0;
56             }
57 0           return PCI_EAT_NONE;
58             }
59              
60             sub S_proxy_close {
61 0     0 0   my ($self, $irc) = splice @_, 0, 2;
62 0           my $client = ${ $_[0] };
  0            
63 0           $self->{clients}--;
64 0 0         if (!$self->{clients}) {
65 0           $irc->yield(away => $self->{Message});
66 0           $self->{away} = 1;
67             }
68 0           return PCI_EAT_NONE;
69             }
70              
71             sub message {
72 0     0 1   my ($self, $value) = @_;
73 0 0         return $self->{Message} if !defined $value;
74 0           $self->{Message} = $value;
75 0           return;
76             }
77              
78             1;
79              
80             =encoding utf8
81              
82             =head1 NAME
83              
84             POE::Component::IRC::Plugin::MultiProxy::Away - A PoCo-IRC plugin which changes the away status based on the presence of proxy clients
85              
86             =head1 SYNOPSIS
87              
88             use POE::Compoent::IRC::Plugin::MultiProxy::Away;
89              
90             $irc->plugin_add('Away', POE::Compoent::IRC::Plugin::MultiProxy::Away->new(Message => "I'm out to lunch"));
91              
92             =head1 DESCRIPTION
93              
94             POE::Compoent::IRC::Plugin::MultiProxy::Away is a
95             L plugin. When the last proxy clien
96             detaches, it changes the status to away, with the supplied away message.
97              
98             This plugin requires the IRC component to be
99             L or a subclass thereof.
100              
101             =head1 METHODS
102              
103             =head2 C
104              
105             One optional argument:
106              
107             B<'Message'>, the away message you want to use. Defaults to 'No clients
108             attached'.
109              
110             Returns a plugin object suitable for feeding to
111             L's C method.
112              
113             =head2 C
114              
115             One optional argument:
116              
117             An away message
118              
119             Changes the away message when called with an argument, returns the current
120             away message otherwise.
121              
122             =head1 AUTHOR
123              
124             Hinrik Ern SigurEsson, hinrik.sig@gmail.com
125              
126             =cut