| 1 | package POE::Component::IRC::Plugin::CTCP; | ||||||||||||||||||||||||||||
| 2 | 4 | $POE::Component::IRC::Plugin::CTCP::VERSION = '6.95'; | |||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use POE::Component::IRC; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use POE::Component::IRC::Plugin qw( :ALL ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=17.5
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 4 | my ($package) = shift; | |||||||||||||||||||||||||||
| 12 | 4 | ▶ | croak "$package requires an even number of arguments" if @_ & 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 13 | 3 | my %args = @_; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | $args{ lc $_ } = delete $args{ $_ } for keys %args; | |||||||||||||||||||||||||||
| 16 | 3 | ▶ | $args{eat} = 1 if !defined ( $args{eat} ) || $args{eat} eq '0'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $args{"eat"} or $args{"eat"} eq 0
MC/DC0%0/2
not defined $args{"eat"} or $args{"eat"} eq 0
not defined $args{"eat"}
$args{"eat"} eq 0
Truth table33%1/3
not(A) or B
A= not defined $args{"eat"}B= $args{"eat"} eq 0
| |||||||||||||||||||||||||||||
| 17 | 3 | return bless \%args, $package; | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 3 | ▶ | sub PCI_register { | ||||||||||||||||||||||||||
|
Subroutine
PCI_register: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 3 | my ($self,$irc) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | $self->{irc} = $irc; | |||||||||||||||||||||||||||
| 24 | 3 | $irc->plugin_register( $self, 'SERVER', qw(ctcp_version ctcp_clientinfo ctcp_userinfo ctcp_time ctcp_ping ctcp_source) ); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 3 | return 1; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 3 | ▶ | sub PCI_unregister { | ||||||||||||||||||||||||||
|
Subroutine
PCI_unregister: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 3 | delete $_[0]->{irc}; | |||||||||||||||||||||||||||
| 31 | 3 | return 1; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | ## no critic (TestingAndDebugging::ProhibitNoStrict) | ||||||||||||||||||||||||||||
| 35 | 1 | ▶ | sub S_ctcp_version { | ||||||||||||||||||||||||||
|
Subroutine
S_ctcp_version: called CC=5 SCAR=17.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 1 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 37 | 1 | my $nick = ( split /!/, ${ $_[0] } )[0]; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | my $our_version; | |||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||
| 41 | 7 | ▶ | no strict 'vars'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | 1 | ▶ | if (defined $POE::Component::IRC::VERSION | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $POE::Component::IRC::VERSION and $POE::Component::IRC::VERSION ne "1, set by base.pm"
MC/DC0%0/2
defined $POE::Component::IRC::VERSION and $POE::Component::IRC::VERSION ne "1, set by base.pm"
defined $POE::Component::IRC::VERSION
$POE::Component::IRC::VERSION ne "1, set by base.pm"
Truth table33%1/3
A and B
A= defined $POE::Component::IRC::VERSIONB= $POE::Component::IRC::VERSION ne "1, set by base.pm"
| |||||||||||||||||||||||||||||
| 43 | && $POE::Component::IRC::VERSION ne '1, set by base.pm') { | ||||||||||||||||||||||||||||
| 44 | 1 | $our_version = 'dev-git'; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | else { | ||||||||||||||||||||||||||||
| 47 | 0 | $our_version = $POE::Component::IRC::VERSION; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | $irc->yield( ctcpreply => $nick => 'VERSION ' . ( defined $self->{version} | ||||||||||||||||||||||||||||
| 52 | ? $self->{version} | ||||||||||||||||||||||||||||
| 53 | 1 | ▶ | : "POE::Component::IRC-$our_version" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | )); | ||||||||||||||||||||||||||||
| 55 | 1 | ▶ | return PCI_EAT_CLIENT if $self->eat(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | return PCI_EAT_NONE; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | ▶ | sub S_ctcp_time { | ||||||||||||||||||||||||||
|
Subroutine
S_ctcp_time: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 1 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 61 | 1 | my $nick = ( split /!/, ${ $_[0] } )[0]; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | $irc->yield(ctcpreply => $nick => strftime('TIME %a, %d %b %Y %H:%M:%S %z', localtime)); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | ▶ | return PCI_EAT_CLIENT if $self->eat(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | return PCI_EAT_NONE; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | ▶ | sub S_ctcp_ping { | ||||||||||||||||||||||||||
|
Subroutine
S_ctcp_ping: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 70 | 1 | my ($self,$irc) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 71 | 1 | my $nick = ( split /!/, ${ $_[0] } )[0]; | |||||||||||||||||||||||||||
| 72 | 1 | my $timestamp = ${ $_[2] }; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 1 | $irc->yield( ctcpreply => $nick => 'PING ' . $timestamp ); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | ▶ | return PCI_EAT_CLIENT if $self->eat(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | return PCI_EAT_NONE; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 1 | ▶ | sub S_ctcp_clientinfo { | ||||||||||||||||||||||||||
|
Subroutine
S_ctcp_clientinfo: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 81 | 1 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 82 | 1 | my $nick = ( split /!/, ${ $_[0] } )[0]; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | $irc->yield(ctcpreply => $nick => 'CLIENTINFO ' . ($self->{clientinfo} | ||||||||||||||||||||||||||||
| 85 | ? $self->{clientinfo} | ||||||||||||||||||||||||||||
| 86 | 1 | ▶ | : 'http://search.cpan.org/perldoc?POE::Component::IRC::Plugin::CTCP' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | )); | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | ▶ | return PCI_EAT_CLIENT if $self->eat(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | return PCI_EAT_NONE; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | ▶ | sub S_ctcp_userinfo { | ||||||||||||||||||||||||||
|
Subroutine
S_ctcp_userinfo: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 94 | 1 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 95 | 1 | my $nick = ( split /!/, ${ $_[0] } )[0]; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 1 | ▶ | $irc->yield( ctcpreply => $nick => 'USERINFO ' . ( $self->{userinfo} ? $self->{userinfo} : 'm33p' ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 1 | ▶ | return PCI_EAT_CLIENT if $self->eat(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | return PCI_EAT_NONE; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 1 | ▶ | sub S_ctcp_source { | ||||||||||||||||||||||||||
|
Subroutine
S_ctcp_source: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 104 | 1 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 105 | 1 | my $nick = ( split /!/, ${ $_[0] } )[0]; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | $irc->yield( ctcpreply => $nick => 'SOURCE ' . ($self->{source} | ||||||||||||||||||||||||||||
| 108 | ? $self->{source} | ||||||||||||||||||||||||||||
| 109 | 1 | ▶ | : 'http://search.cpan.org/dist/POE-Component-IRC' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | )); | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 1 | ▶ | return PCI_EAT_CLIENT if $self->eat(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | return PCI_EAT_NONE; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 6 | ▶ | sub eat { | ||||||||||||||||||||||||||
|
Subroutine
eat: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 118 | 6 | my $value = shift; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 6 | ▶ | return $self->{eat} if !defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | return $self->{eat} = $value; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 4 | 1; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =encoding utf8 | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =head1 NAME | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | POE::Component::IRC::Plugin::CTCP - A PoCo-IRC plugin that auto-responds to CTCP requests | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | use strict; | ||||||||||||||||||||||||||||
| 135 | use warnings; | ||||||||||||||||||||||||||||
| 136 | use POE qw(Component::IRC Component::IRC::Plugin::CTCP); | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | my $nickname = 'Flibble' . $$; | ||||||||||||||||||||||||||||
| 139 | my $ircname = 'Flibble the Sailor Bot'; | ||||||||||||||||||||||||||||
| 140 | my $ircserver = 'irc.blahblahblah.irc'; | ||||||||||||||||||||||||||||
| 141 | my $port = 6667; | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | my $irc = POE::Component::IRC->spawn( | ||||||||||||||||||||||||||||
| 144 | nick => $nickname, | ||||||||||||||||||||||||||||
| 145 | server => $ircserver, | ||||||||||||||||||||||||||||
| 146 | port => $port, | ||||||||||||||||||||||||||||
| 147 | ircname => $ircname, | ||||||||||||||||||||||||||||
| 148 | ) or die "Oh noooo! $!"; | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | POE::Session->create( | ||||||||||||||||||||||||||||
| 151 | package_states => [ | ||||||||||||||||||||||||||||
| 152 | main => [ qw(_start) ], | ||||||||||||||||||||||||||||
| 153 | ], | ||||||||||||||||||||||||||||
| 154 | ); | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | $poe_kernel->run(); | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | sub _start { | ||||||||||||||||||||||||||||
| 159 | # Create and load our CTCP plugin | ||||||||||||||||||||||||||||
| 160 | $irc->plugin_add( 'CTCP' => POE::Component::IRC::Plugin::CTCP->new( | ||||||||||||||||||||||||||||
| 161 | version => $ircname, | ||||||||||||||||||||||||||||
| 162 | userinfo => $ircname, | ||||||||||||||||||||||||||||
| 163 | )); | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | $irc->yield( register => 'all' ); | ||||||||||||||||||||||||||||
| 166 | $irc->yield( connect => { } ); | ||||||||||||||||||||||||||||
| 167 | return: | ||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | POE::Component::IRC::Plugin::CTCP is a L<POE::Component::IRC|POE::Component::IRC> | ||||||||||||||||||||||||||||
| 173 | plugin. It watches for C<irc_ctcp_version>, C<irc_ctcp_userinfo>, | ||||||||||||||||||||||||||||
| 174 | C<irc_ctcp_ping>, C<irc_ctcp_time> and C<irc_ctcp_source> events and | ||||||||||||||||||||||||||||
| 175 | autoresponds on your behalf. | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | =head1 METHODS | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =head2 C<new> | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | Takes a number of optional arguments: | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | B<'version'>, a string to send in response to C<irc_ctcp_version>. Default is | ||||||||||||||||||||||||||||
| 184 | PoCo-IRC and version; | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | B<'clientinfo'>, a string to send in response to C<irc_ctcp_clientinfo>. | ||||||||||||||||||||||||||||
| 187 | Default is L<http://search.cpan.org/perldoc?POE::Component::IRC::Plugin::CTCP>. | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | B<'userinfo'>, a string to send in response to C<irc_ctcp_userinfo>. Default | ||||||||||||||||||||||||||||
| 190 | is 'm33p'; | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | B<'source'>, a string to send in response to C<irc_ctcp_source>. Default is | ||||||||||||||||||||||||||||
| 193 | L<http://search.cpan.org/dist/POE-Component-IRC>. | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | B<'eat'>, by default the plugin uses PCI_EAT_CLIENT, set this to 0 to disable | ||||||||||||||||||||||||||||
| 196 | this behaviour; | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | Returns a plugin object suitable for feeding to | ||||||||||||||||||||||||||||
| 199 | L<POE::Component::IRC|POE::Component::IRC>'s C<plugin_add> method. | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | =head2 C<eat> | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | With no arguments, returns true or false on whether the plugin is "eating" CTCP | ||||||||||||||||||||||||||||
| 204 | events that it has dealt with. An argument will set "eating" to on or off | ||||||||||||||||||||||||||||
| 205 | appropriately, depending on whether the value is true or false. | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | Chris 'BinGOs' Williams | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | CTCP Specification L<http://www.irchelp.org/irchelp/rfc/ctcpspec.html>. | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | =cut | ||||||||||||||||||||||||||||