File Coverage

blib/lib/POE/Component/IRC/Plugin/NickServID.pm
Criterion Covered Total %
statement 26 56 46.4
branch 2 14 14.2
condition 0 3 0.0
subroutine 8 12 66.6
pod 1 7 14.2
total 37 92 40.2


line stmt bran cond sub pod time code
1             package POE::Component::IRC::Plugin::NickServID;
2             our $AUTHORITY = 'cpan:HINRIK';
3             $POE::Component::IRC::Plugin::NickServID::VERSION = '6.92';
4 2     2   1947 use strict;
  2         6  
  2         81  
5 2     2   13 use warnings FATAL => 'all';
  2         4  
  2         103  
6 2     2   13 use Carp;
  2         5  
  2         154  
7 2     2   23 use IRC::Utils qw( uc_irc parse_user );
  2         6  
  2         157  
8 2     2   35 use POE::Component::IRC::Plugin qw( :ALL );
  2         6  
  2         1864  
9              
10             sub new {
11 1     1 1 360 my ($package) = shift;
12 1 50       5 croak "$package requires an even number of arguments" if @_ & 1;
13 1         4 my %self = @_;
14              
15 1 50       4 die "$package requires a Password" if !defined $self{Password};
16 1         4 return bless \%self, $package;
17             }
18              
19             sub PCI_register {
20 1     1 0 810 my ($self, $irc) = @_;
21 1         4 $self->{nick} = $irc->{nick};
22 1         3 $self->{irc} = $irc;
23 1         4 $irc->plugin_register($self, 'SERVER', qw(isupport nick notice));
24 1         42 return 1;
25             }
26              
27             sub PCI_unregister {
28 1     1 0 598 return 1;
29             }
30              
31             # we identify after S_isupport so that pocoirc has a chance to turn on
32             # CAPAB IDENTIFY-MSG (if the server supports it) before the AutoJoin
33             # plugin joins channels
34             sub S_isupport {
35 0     0 0   my ($self, $irc) = splice @_, 0, 2;
36 0           $irc->yield(nickserv => "IDENTIFY $self->{Password}");
37 0           return PCI_EAT_NONE;
38             }
39              
40             sub S_nick {
41 0     0 0   my ($self, $irc) = splice @_, 0, 2;
42 0           my $mapping = $irc->isupport('CASEMAPPING');
43 0           my $new_nick = uc_irc( ${ $_[1] }, $mapping );
  0            
44              
45 0 0         if ( $new_nick eq uc_irc($self->{nick}, $mapping) ) {
46 0           $irc->yield(nickserv => "IDENTIFY $self->{Password}");
47             }
48 0           return PCI_EAT_NONE;
49             }
50              
51             sub S_notice {
52 0     0 0   my ($self, $irc) = splice @_, 0, 2;
53 0           my $sender = parse_user(${ $_[0] });
  0            
54 0           my $recipient = parse_user(${ $_[1] }->[0]);
  0            
55 0           my $msg = ${ $_[2] };
  0            
56              
57 0 0         return PCI_EAT_NONE if $recipient ne $irc->nick_name();
58 0 0         return PCI_EAT_NONE if $sender !~ /^nickserv$/i;
59 0 0         return PCI_EAT_NONE if $msg !~ /now (?:identified|recognized)/;
60 0           $irc->send_event_next('irc_identified');
61 0           return PCI_EAT_NONE;
62             }
63              
64             # ERR_NICKNAMEINUSE
65             sub S_433 {
66 0     0 0   my ($self, $irc) = splice @_, 0, 2;
67 0           my $offending = ${ $_[2] }->[0];
  0            
68 0           my $reason = ${ $_[2] }->[1];
  0            
69              
70 0 0 0       if ($irc->nick_name() eq $offending && $reason eq "Nickname is registered to someone else") {
71 0           $irc->yield(nickserv => "IDENTIFY $self->{Password}");
72             }
73              
74 0           return PCI_EAT_NONE;
75             }
76             1;
77              
78             =encoding utf8
79              
80             =head1 NAME
81              
82             POE::Component::IRC::Plugin::NickServID - A PoCo-IRC plugin which identifies with NickServ when needed
83              
84             =head1 SYNOPSIS
85              
86             use POE::Component::IRC::Plugin::NickServID;
87              
88             $irc->plugin_add( 'NickServID', POE::Component::IRC::Plugin::NickServID->new(
89             Password => 'opensesame'
90             ));
91              
92             =head1 DESCRIPTION
93              
94             POE::Component::IRC::Plugin::NickServID is a L
95             plugin. It identifies with NickServ on connect and when you change your nick,
96             if your nickname matches the supplied password.
97              
98             B: If you have a cloak and you don't want to be seen without it, make sure
99             you don't join channels until after you've identified yourself. If you use the
100             L, it will be taken
101             care of for you.
102              
103             =head1 METHODS
104              
105             =head2 C
106              
107             Arguments:
108              
109             'Password', the NickServ password.
110              
111             Returns a plugin object suitable for feeding to
112             L's plugin_add() method.
113              
114             =head1 OUTPUT EVENTS
115              
116             =head2 C
117              
118             This event will be sent when you have identified with NickServ. No arguments
119             are passed with it.
120              
121             =head1 AUTHOR
122              
123             Hinrik Ern SigurEsson, hinrik.sig@gmail.com
124              
125             =cut