blib/lib/Bot/IRC/X/Message.pm

filter: Statementstmt 52.7% 19 / 36 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 1 totaltotal 44.4% 24 / 54 CC 5 SCAR 21.8
CC
5
Cov
43%
__ANON__
20.0
__ANON__
6.0
init
1.5
CRAP 8.9
↑ Summary
1 package Bot::IRC::X::Message;
2 # ABSTRACT: Bot::IRC plugin for leaving messages for nicks
3  
4 2 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use exact;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use DateTime::Format::Human::Duration;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '1.09'; # VERSION
11  
12 1 ▶sub init {
Subroutine init: called CC=1 SCAR=4.2
Pod undocumented
13 1 my ($bot) = @_;
14 1 $bot->load('Store');
15  
16 $bot->hook(
17 {
18 to_me => 1,
19 text => qr/^(?:message|tell|ask)\s+(?<nick>\S+)\s+(?<msg>.+)\s*/,
20 },
21 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
22 0 my ( $bot, $in, $m ) = @_;
23  
24 0 my $nick = lc( $m->{nick} );
25 0 ▶ my @msgs = @{ $bot->store->get($nick) || [] };
Condition0%0/2
$bot->store->get($nick) || []
l!l
00
MC/DC0%0/1
$bot->store->get($nick) || []
$bot->store->get($nick)
Truth table0%0/2
A
A= $bot->store->get($nick)
Aresult
11
00
26  
27 push( @msgs, {
28 in => $in,
29 time => time,
30 msg => $m->{msg},
31 0 } );
32 0 $bot->store->set( $nick => \@msgs );
33  
34 0 $bot->reply_to('OK.');
35 },
36 1 );
37  
38 1 my $duration = DateTime::Format::Human::Duration->new;
39 $bot->hook(
40 {
41 command => 'JOIN',
42 },
43 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
44 0 my ( $bot, $in ) = @_;
45  
46 0 my $nick = lc( $in->{nick} );
47 0 ▶ my @msgs = @{ $bot->store->get($nick) || [] };
Condition0%0/2
$bot->store->get($nick) || []
l!l
00
MC/DC0%0/1
$bot->store->get($nick) || []
$bot->store->get($nick)
Truth table0%0/2
A
A= $bot->store->get($nick)
Aresult
11
00
48  
49 0 $bot->store->set( $nick => [] );
50  
51 0 ▶ for ( my $i = 0; $i < @msgs; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @msgs) 0 0 0
52 $bot->reply_to(
53 "$msgs[$i]->{in}{nick} left a message for you " .
54 $duration->format_duration_between(
55 0 map { DateTime->from_epoch( epoch => $_ ) } $msgs[$i]->{time}, time
56 0 ) .
57 " ago. \"$msgs[$i]->{msg}\""
58 );
59 0 ▶ sleep 1 if ( $i + 1 < @msgs );
Branch: 1 branch
BranchTrueFalseTotal
if $i + 1 < @msgs 0 0 0
60 }
61  
62 0 return;
63 },
64 1 );
65  
66 1 $bot->helps( message => 'Leave a message for a nick. Usage: <bot nick> message <target nick> <message>');
67 }
68  
69 2 1;
70  
71 __END__
↑ Summary