blib/lib/App/SmokeBox/Mini/Plugin/IRC.pm

filter: Statementstmt 21.1% 15 / 71 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 28.5% 4 / 14 Podpod 0.0% 0 / 7 totaltotal 17.1% 19 / 111 CC 13 SCAR 23.3
CC
13
Cov
17%
init
30.0
irc_join
12.0
_start_up
6.0
CRAP 10.2
↑ Summary
1 package App::SmokeBox::Mini::Plugin::IRC;
2 {
3 1 $App::SmokeBox::Mini::Plugin::IRC::VERSION = '0.12';
4 }
5  
6 #ABSTRACT: IRC plugin for minismokebox
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use POE qw[Component::IRC Component::IRC::Plugin::Connector Component::IRC::Plugin::CTCP];
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use POE::Component::IRC::Common qw[u_irc];
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub init {
Subroutine init: not called CC=5 SCAR=34.0
Pod undocumented
14 0 my $package = shift;
15 0 my $config = shift;
16 0 ▶ return unless $config and ref $config eq 'Config::Tiny';
Branch: 1 branch
BranchTrueFalseTotal
unless $config and ref $config eq "Config::Tiny" 0 0 0
Condition0%0/3
$config and ref $config eq "Config::Tiny"
!ll&&!rl&&r
000
MC/DC0%0/2
$config and ref $config eq "Config::Tiny"
$config ref $config eq "Config::Tiny"
Truth table0%0/3
A and B
A= $configB= ref $config eq "Config::Tiny"
ABresult
0X0
100
111
17 0 ▶ return unless $config->{IRC};
Branch: 1 branch
BranchTrueFalseTotal
unless $config->{"IRC"} 0 0 0
18 0 ▶ return unless $config->{IRC}->{server};
Branch: 1 branch
BranchTrueFalseTotal
unless $config->{"IRC"}{"server"} 0 0 0
19 0 my $heap = $config->{IRC};
20 0 POE::Session->create(
21 package_states => [
22 __PACKAGE__, [qw(_start _start_up irc_registered irc_001 irc_join sbox_smoke sbox_stop sbox_perl_info)],
23 ],
24 heap => $heap,
25 );
26 }
27  
28 0 ▶sub _start {
Subroutine _start: not called CC=1 SCAR=6.9
29 0 my ($kernel,$heap) = @_[KERNEL,HEAP];
30 0 $kernel->refcount_increment( $_[SESSION]->ID(), __PACKAGE__ );
31 0 $kernel->yield( '_start_up' );
32 0 return;
33 }
34  
35 0 ▶sub _start_up {
Subroutine _start_up: not called CC=2 SCAR=17.9
36 0 my ($kernel,$heap) = @_[KERNEL,HEAP];
37 0 ▶ $heap->{nick} = $^O . $$ unless $heap->{nick};
Branch: 1 branch
BranchTrueFalseTotal
unless $heap->{"nick"} 0 0 0
38 my $irc = POE::Component::IRC->spawn(
39 0 ( map { ( $_, $heap->{$_} ) } grep { exists $heap->{$_} } qw(server nick ircname username port password) ),
40 );
41 0 $heap->{_irc} = $irc;
42 0 return;
43 }
44  
45 0 ▶sub irc_registered {
Subroutine irc_registered: not called CC=1 SCAR=6.9
Pod undocumented
46 0 my ($kernel,$heap,$irc) = @_[KERNEL,HEAP,ARG0];
47 0 $irc->plugin_add( 'Connector', POE::Component::IRC::Plugin::Connector->new() );
48 0 $irc->yield( 'connect', { } );
49 0 return;
50 }
51  
52 0 ▶sub irc_001 {
Subroutine irc_001: not called CC=2 SCAR=17.9
Pod undocumented
53 0 my ($kernel,$heap,$sender) = @_[KERNEL,HEAP,SENDER];
54 0 $kernel->post( $sender, 'join', $_ ) for _get_channels( $heap->{channels} );
55 0 return;
56 }
57  
58 0 ▶sub irc_join {
Subroutine irc_join: not called CC=3 SCAR=24.8
Pod undocumented
59 0 my ($kernel,$heap,$sender) = @_[KERNEL,HEAP,SENDER];
60 0 my $map = $heap->{_irc}->isupport('CASEMAPPING');
61 0 my $unick = u_irc( ( split /!/, $_[ARG0] )[0], $map );
62 0 my $chan = $_[ARG1];
63 0 ▶ return unless $unick eq u_irc( $heap->{_irc}->nick_name(), $map );
Branch: 1 branch
BranchTrueFalseTotal
unless $unick eq u_irc($heap->{"_irc"}->nick_name, $map) 0 0 0
64 0 ▶ return unless $heap->{_msg};
Branch: 1 branch
BranchTrueFalseTotal
unless $heap->{"_msg"} 0 0 0
65 0 $kernel->post( $sender, 'privmsg', $chan, $heap->{_msg} );
66 0 return;
67 }
68  
69 0 ▶sub _get_channels {
Subroutine _get_channels: not called CC=2 SCAR=17.9
70 0 my $channels = shift;
71 0 my @channels;
72 0 ▶ unless ( $channels ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($channels) { } 0 0 0
73 0 push @channels, '#smokebox';
74 }
75 else {
76 0 push @channels, split(/\,/, $channels);
77 }
78 0 return @channels;
79 }
80  
81 0 ▶sub sbox_perl_info {
Subroutine sbox_perl_info: not called CC=2 SCAR=17.9
Pod undocumented
82 0 my ($kernel,$heap,$vers,$arch,$osvers) = @_[KERNEL,HEAP,ARG0,ARG1,ARG2];
83 0 my $message = "Smoking v$vers built for $arch $osvers";
84 0 $heap->{_msg} = $message;
85 0 $heap->{_irc}->yield( 'privmsg', $_, $message ) for _get_channels( $heap->{channels} );
86 0 $heap->{_irc}->plugin_add( 'CTCP',
87 POE::Component::IRC::Plugin::CTCP->new(
88 version => $message,
89 userinfo => $message,
90 )
91 );
92 0 return;
93 }
94  
95 0 ▶sub sbox_smoke {
Subroutine sbox_smoke: not called CC=2 SCAR=17.9
Pod undocumented
96 0 my ($kernel,$heap,$data) = @_[KERNEL,HEAP,ARG0];
97 0 my $dist = $data->{job}->module();
98 0 my ($result) = $data->{result}->results;
99 0 my $message = "Distribution: '$dist' finished with status '$result->{status}'";
100 0 $heap->{_irc}->yield( 'privmsg', $_, $message ) for _get_channels( $heap->{channels} );
101 0 return;
102 }
103  
104 0 ▶sub sbox_stop {
Subroutine sbox_stop: not called CC=2 SCAR=17.9
Pod undocumented
105 0 my ($kernel,$heap,@stats) = @_[KERNEL,HEAP,ARG0..$#_];
106 0 $kernel->refcount_decrement( $_[SESSION]->ID(), __PACKAGE__ );
107 0 $heap->{_irc}->yield( 'privmsg', $_, 'Smoker finished: ' . join(',', @stats) ) for
108 _get_channels( $heap->{channels} );
109 0 $heap->{_irc}->delay( [ 'shutdown' ], 5 );
110 0 return;
111 }
112  
113 1 qq[Smokey IRC];
114  
115 __END__
↑ Summary