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