Plugin/Thanks.pm

filter: Statementstmt 26.4% 14 / 53 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 40.0% 4 / 10 Podpod 0.0% 0 / 4 totaltotal 19.3% 18 / 93 CC 13 SCAR 35.3
CC
13
Cov
19%
S_public
72.0
new
30.0
_make_thanks_response
6.0
CRAP 34.0
« Plugin/AlarmClock.pm ↑ Summary Plugin/SigFail.pm »
1 package POE::Component::IRC::Plugin::Thanks;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '1.001003'; # VERSION
7  
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use POE::Component::IRC::Plugin qw( :ALL );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
12 0 my $package = shift;
13 0 ▶ croak "Must have even number of arguments to constructor"
Branch: 1 branch
BranchTrueFalseTotal
if @_ & 1 0 0 0
14 if @_ & 1;
15  
16 0 my %args = @_;
17  
18 0 $args{ lc $_ } = delete $args{ $_ } for keys %args;
19  
20 # fill in defaults
21 0 %args = (
22 trigger => qr/ ^ (?:thank s? (?: \s* you )? | th?a?nx | thx | tyvm )/xi,
23 respond => 1,
24 thanks_event => 'thanks_response',
25  
26 %args,
27 );
28 0 my $self = bless \%args, $package;
29  
30 0 ▶ unless ( $self->{messages} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"messages"}) 0 0 0
31 0 $self->{messages} = $self->_make_default_messages;
32 }
33  
34 0 ▶ push @{ $self->{messages} }, @{ $self->{extra_messages} || [] };
Condition0%0/2
$self->{'extra_messages'} || []
l!l
00
MC/DC0%0/1
$self->{'extra_messages'} || []
$self->{'extra_messages'}
Truth table0%0/2
A
A= $self->{'extra_messages'}
Aresult
11
00
35  
36 0 return $self;
37 }
38  
39 0 ▶sub PCI_register {
Subroutine PCI_register: not called CC=1 SCAR=6.9
Pod undocumented
40 0 my ( $self, $irc ) = splice @_, 0, 2;
41  
42 0 $irc->plugin_register( $self, 'SERVER', qw(public) );
43 0 return 1;
44 }
45  
46 0 ▶sub PCI_unregister {
Subroutine PCI_unregister: not called CC=1 SCAR=6.9
Pod undocumented
47 0 return 1;
48 }
49  
50 0 ▶sub S_public {
Subroutine S_public: not called CC=8 SCAR=42.8
Pod undocumented
51 0 my ( $self, $irc ) = splice @_, 0, 2;
52 0 my $who = ${ $_[0] };
53 0 my $nick = ( split /!/, $who )[0];
54 0 my $channel = ${ $_[1] }->[0];
55 0 my $what = ${ $_[2] };
56 0 my $mynick = $irc->nick_name();
57  
58 0 ▶ foreach my $ban_re ( @{ $self->{bans} || [] } ) {
Condition0%0/2
$self->{'bans'} || []
l!l
00
MC/DC0%0/1
$self->{'bans'} || []
$self->{'bans'}
Truth table0%0/2
A
A= $self->{'bans'}
Aresult
11
00
59 0 ▶ return PCI_EAT_NONE
Branch: 1 branch
BranchTrueFalseTotal
if $who =~ /$ban_re/ 0 0 0
60 if $who =~ /$ban_re/;
61 }
62  
63 0 my ( $message ) = $what =~ /^\s*\Q$mynick\E[:,;.~]?\s*(.*)$/i;
64 return PCI_EAT_NONE
65 0 ▶ unless defined $message and $message =~ $self->{trigger};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message and $message =~ /$self->{"trigger"}/ 0 0 0
Condition0%0/3
defined $message and $message =~ /$self->{"trigger"}/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $message and $message =~ /$self->{"trigger"}/
defined $message $message =~ /$self->{"trigger"}/
Truth table0%0/3
A and B
A= defined $messageB= $message =~ /$self->{"trigger"}/
ABresult
0X0
100
111
66  
67 0 my $thanks_response = $self->_make_thanks_response;
68 $irc->yield( privmsg => $channel => "$nick, $thanks_response" )
69 0 ▶ if $self->{respond};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"respond"} 0 0 0
70  
71 $irc->_send_event( $self->{thanks_event} => {
72 0 who => $who,
73 channel => $channel,
74 what => $what,
75 response => $thanks_response,
76 }
77 );
78  
79 0 ▶ return $self->{eat} ? PCI_EAT_ALL : PCI_EAT_NONE;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'eat'} ? : 0 0 0
80 }
81  
82 0 ▶sub _make_thanks_response {
Subroutine _make_thanks_response: not called CC=2 SCAR=17.9
83 0 my $self = shift;
84 0 ▶ my @messages = @{ $self->{messages} || [] };
Condition0%0/2
$self->{'messages'} || []
l!l
00
MC/DC0%0/1
$self->{'messages'} || []
$self->{'messages'}
Truth table0%0/2
A
A= $self->{'messages'}
Aresult
11
00
85 0 return $messages[ rand @messages ];
86 }
87  
88 0 ▶sub _make_default_messages {
Subroutine _make_default_messages: not called CC=1 SCAR=6.9
89 return [
90 0 q|You are welcome!|,
91 q|That will be $50... CASH!|,
92 q|yeah, yeah, that's what you all say...|,
93 q|No problema :)|,
94 q|can you help _me_ now?|,
95 q|FYI, thanking the bot says a lot about your mental state!|,
96 q|It's ok, I'm just a bot, no need for "thank you"s.|,
97 q|No, no, thank YOU|,
98 ],
99 }
100  
101 1 1;
102  
103 __END__
« Plugin/AlarmClock.pm ↑ Summary Plugin/SigFail.pm »