line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Bondage::Away; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
27
|
$App::Bondage::Away::AUTHORITY = 'cpan:HINRIK'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
7
|
1
|
|
|
1
|
|
6
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
8
|
1
|
|
|
1
|
|
656
|
use POE::Component::IRC::Plugin qw( :ALL ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.1'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
|
|
|
|
|
|
my ($package, %self) = @_; |
14
|
|
|
|
|
|
|
return bless \%self, $package; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub PCI_register { |
18
|
|
|
|
|
|
|
my ($self, $irc) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
if (!$irc->isa('POE::Component::IRC::State')) { |
21
|
|
|
|
|
|
|
die __PACKAGE__ . " requires PoCo::IRC::State or a subclass thereof\n"; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$self->{Message} = 'No clients attached' unless defined $self->{Message}; |
25
|
|
|
|
|
|
|
$self->{clients} = 0; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
if ($irc->connected() && $irc->is_away($irc->nick_name())) { |
28
|
|
|
|
|
|
|
$self->{away} = 1; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$irc->plugin_register($self, 'SERVER', qw(001 proxy_authed proxy_close)); |
32
|
|
|
|
|
|
|
return 1; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub PCI_unregister { |
36
|
|
|
|
|
|
|
return 1; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub S_001 { |
40
|
|
|
|
|
|
|
my ($self, $irc) = splice @_, 0, 2; |
41
|
|
|
|
|
|
|
if (!$self->{clients}) { |
42
|
|
|
|
|
|
|
$irc->yield(away => $self->{Message}); |
43
|
|
|
|
|
|
|
$self->{away} = 1; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
return PCI_EAT_NONE; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub S_proxy_authed { |
49
|
|
|
|
|
|
|
my ($self, $irc) = splice @_, 0, 2; |
50
|
|
|
|
|
|
|
my $client = ${ $_[0] }; |
51
|
|
|
|
|
|
|
$self->{clients}++; |
52
|
|
|
|
|
|
|
if ($self->{away}) { |
53
|
|
|
|
|
|
|
$irc->yield('away'); |
54
|
|
|
|
|
|
|
$self->{away} = 0; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
return PCI_EAT_NONE; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub S_proxy_close { |
60
|
|
|
|
|
|
|
my ($self, $irc) = splice @_, 0, 2; |
61
|
|
|
|
|
|
|
my $client = ${ $_[0] }; |
62
|
|
|
|
|
|
|
$self->{clients}--; |
63
|
|
|
|
|
|
|
if (!$self->{clients}) { |
64
|
|
|
|
|
|
|
$irc->yield(away => $self->{Message}); |
65
|
|
|
|
|
|
|
$self->{away} = 1; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
return PCI_EAT_NONE; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub message { |
71
|
|
|
|
|
|
|
my ($self, $value) = @_; |
72
|
|
|
|
|
|
|
return $self->{Message} if !defined $value; |
73
|
|
|
|
|
|
|
$self->{Message} = $value; |
74
|
|
|
|
|
|
|
return; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=encoding utf8 |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 NAME |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
App::Bondage::Away - A PoCo-IRC plugin which changes the away status |
84
|
|
|
|
|
|
|
based on the presence of proxy clients. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SYNOPSIS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
use App::Bondage::Away; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$irc->plugin_add('Away', App::Bondage::Away->new(Message => "I'm out to lunch")); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 DESCRIPTION |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
App::Bondage::Away is a L plugin. |
95
|
|
|
|
|
|
|
When the last proxy client detaches, it changes the status to away, with |
96
|
|
|
|
|
|
|
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 |