IRC/Join.pm

filter: Statementstmt 39.3% 24 / 61 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 40.0% 4 / 10 Podpod 0.0% 0 / 1 totaltotal 27.7% 28 / 101 CC 15 SCAR 30.6
CC
15
Cov
29%
__ANON__
56.0
__ANON__
12.0
__ANON__
12.0
CRAP 21.3
« IRC/Store/SQLite.pm ↑ Summary IRC/Store.pm »
1 package Bot::IRC::Join;
2 # ABSTRACT: Bot::IRC join and part channels and remember channels state
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 our $VERSION = '1.49'; # VERSION
8  
9 1 ▶sub init {
Subroutine init: called CC=2 SCAR=13.6
Pod undocumented
10 1 my ($bot) = @_;
11 1 $bot->load('Store');
12  
13 $bot->hook(
14 {
15 to_me => 1,
16 text => qr/^join\s+(?<channel>\S+)/i,
17 },
18 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
19 0 my ( $bot, $in, $m ) = @_;
20  
21 0 ▶ if ( $m->{channel} =~ /^#\w+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->{'channel'} =~ /^#\w+$/u) { } 0 0 0
22 0 $bot->reply( 'I will attempt to join: ' . $m->{channel} );
23 0 $bot->join( $m->{channel} );
24 }
25 else {
26 0 $bot->reply_to( '"' . $m->{channel} . q{" doesn't appear to be a channel I can join.} );
27 }
28 },
29 1 );
30  
31 $bot->hook(
32 {
33 to_me => 1,
34 text => qr/^(?:part|leave)\s+(?<channel>\S+)/i,
35 },
36 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
37 0 my ( $bot, $in, $m ) = @_;
38  
39 0 ▶ if ( $m->{channel} =~ /^#\w+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->{'channel'} =~ /^#\w+$/u) { } 0 0 0
40 0 $bot->reply_to( 'I will depart: ' . $m->{channel} );
41 0 $bot->part( $m->{channel} );
42 }
43 else {
44 0 $bot->reply_to( '"' . $m->{channel} . q{" doesn't appear to be a valid channel name.} );
45 }
46 },
47 1 );
48  
49 $bot->hook(
50 {
51 to_me => 1,
52 text => qr/^channels\b/i,
53 },
54 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
55 0 my ($bot) = @_;
56 0 ▶ my @channels = @{ $bot->store->get('channels') || [] };
Condition0%0/2
$bot->store->get('channels') || []
l!l
00
MC/DC0%0/1
$bot->store->get('channels') || []
$bot->store->get('channels')
Truth table0%0/2
A
A= $bot->store->get('channels')
Aresult
11
00
57  
58 $bot->reply_to(
59 (@channels)
60 ? 'I am currently in the following channels: ' .
61 0 ▶ $bot->list( ', ', 'and', sort { $a cmp $b } @channels ) . '.'
Branch: 1 branch
BranchTrueFalseTotal
@channels ? : 0 0 0
62 : 'I am currently not in any channels.'
63 );
64 },
65 1 );
66  
67 1 $bot->helps( join => 'Join and part channels. Usage: join <channel>, part <channel>, channels.' );
68  
69 {
70 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
71 1 for ( qw( join part ) ) {
72 2 my $name = ref($bot) . '::' . $_;
73 2 *{ $name . '_super' } = *$name{CODE};
74 }
75 }
76  
77 $bot->subs(
78 0 ▶ join => sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
79 0 my $bot = shift;
80 0 my @channels = @_;
81 0 ▶ my %channels = map { $_ => 1 } @{ $bot->store->get('channels') || [] };
Condition0%0/2
$bot->store->get('channels') || []
l!l
00
MC/DC0%0/1
$bot->store->get('channels') || []
$bot->store->get('channels')
Truth table0%0/2
A
A= $bot->store->get('channels')
Aresult
11
00
82 0 ▶ @channels = keys %channels unless (@channels);
Branch: 1 branch
BranchTrueFalseTotal
unless @channels 0 0 0
83  
84 0 my $join = $bot->settings('connect')->{join};
85 0 ▶ if ( not @channels and $join ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @channels and $join) 0 0 0
Condition0%0/3
not @channels and $join
!ll&&!rl&&r
000
MC/DC0%0/2
not @channels and $join
not @channels $join
Truth table0%0/3
not(A) and B
A= not @channelsB= $join
ABresult
0X0
100
111
86 0 ▶ @channels = ( ref $join eq 'ARRAY' ) ? @$join : $join
Branch: 1 branch
BranchTrueFalseTotal
ref $join eq 'ARRAY' ? : 0 0 0
87 }
88  
89 0 $bot->join_super(@channels);
90  
91 0 $channels{$_} = 1 for (@channels);
92 0 $bot->store->set( 'channels' => [ keys %channels ] );
93  
94 0 return $bot;
95 },
96 1 );
97  
98 $bot->subs(
99 0 ▶ part => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
100 0 my $bot = shift;
101 0 ▶ my %channels = map { $_ => 1 } @{ $bot->store->get('channels') || [] };
Condition0%0/2
$bot->store->get('channels') || []
l!l
00
MC/DC0%0/1
$bot->store->get('channels') || []
$bot->store->get('channels')
Truth table0%0/2
A
A= $bot->store->get('channels')
Aresult
11
00
102  
103 0 $bot->part_super(@_);
104  
105 0 delete $channels{$_} for (@_);
106 0 $bot->store->set( 'channels' => [ keys %channels ] );
107  
108 0 return $bot;
109 },
110 1 );
111  
112 $bot->subs(
113 0 ▶ channels => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
114 0 ▶ return shift->store->get('channels') || [];
Condition0%0/2
(shift())->store->get('channels') || []
l!l
00
MC/DC0%0/1
(shift())->store->get('channels') || []
(shift())->store->get('channels')
Truth table0%0/2
A
A= (shift())->store->get('channels')
Aresult
11
00
115 },
116 1 );
117 }
118  
119 2 1;
120  
121 __END__
« IRC/Store/SQLite.pm ↑ Summary IRC/Store.pm »