blib/lib/POE/Component/IRC/Plugin/POE/Knee.pm

filter: Statementstmt 47.6% 50 / 105 Branchbran 6.2% 1 / 16 Conditioncond 16.6% 2 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 76.4% 13 / 17 Podpod 25.0% 1 / 4 totaltotal 41.8% 67 / 160 SCAR 41.6
CC
15
Cov
40%
_race_on
30.0
S_public
20.0
_run
12.0
CRAP 64.0
↑ Summary
1 package POE::Component::IRC::Plugin::POE::Knee;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Time::HiRes qw(gettimeofday);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Math::Random;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use POE::Component::IRC::Plugin qw(:ALL);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use POE::Component::IRC::Common qw(:ALL);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 $VERSION = '1.08';
13  
14 sub new {
15 1 ▶ my $package = shift;
Subroutine new: called CC=5 SCAR=20.1
Pod documented
16 1 my %args = @_;
17 1 $args{lc $_} = delete $args{$_} for keys %args;
18 1 ▶ $args{stages} = 5 unless $args{stages} and $args{stages} =~ /^\d+$/ and $args{stages} <= 30;
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"stages"} and $args{"stages"} =~ /^\d+$/ and $args{"stages"} <= 30 0 0 0
Condition33%2/6
$args{"stages"} and $args{"stages"} =~ /^\d+$/ and $args{"stages"} <= 30
!ll&&!rl&&r
100
$args{"stages"} and $args{"stages"} =~ /^\d+$/
!ll&&!rl&&r
100
MC/DC0%0/3
$args{"stages"} and $args{"stages"} =~ /^\d+$/ and $args{"stages"} <= 30
$args{"stages"} $args{"stages"} =~ /^\d+$/ $args{"stages"} <= 30
Truth table25%1/4
A and B and C
A= $args{"stages"}B= $args{"stages"} =~ /^\d+$/C= $args{"stages"} <= 30
ABCresult
0XX0
10X0
1100
1111
19 1 bless \%args, $package;
20 }
21  
22 sub PCI_register {
23 1 ▶ my ($self,$irc) = @_;
Subroutine PCI_register: called CC=2 SCAR=7.0
Pod undocumented
24 1 ▶ die "This plugin must be used with POE::Component::IRC::State or a subclass of that\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $irc->isa("POE::Component::IRC::State") 0 1 1
25 unless $irc->isa('POE::Component::IRC::State');
26 1 $self->{irc} = $irc;
27 1 $irc->plugin_register( $self, 'SERVER', qw(public) );
28 1 $self->{session_id} = POE::Session->create(
29 object_states => [
30 $self => [ qw(_shutdown _start _race_on _run) ],
31 ],
32 )->ID();
33 1 return 1;
34 }
35  
36 sub PCI_unregister {
37 1 ▶ my ($self,$irc) = splice @_, 0, 2;
Subroutine PCI_unregister: called CC=1 SCAR=0.0
Pod undocumented
38 1 $poe_kernel->call( $self->{session_id} => '_shutdown' );
39 1 delete $self->{irc};
40 1 return 1;
41 }
42  
43 sub S_public {
44 0 ▶ my ($self,$irc) = splice @_, 0, 2;
Subroutine S_public: not called CC=4 SCAR=30.0
Pod undocumented
45 0 my ($nick,$userhost) = ( split /!/, ${ $_[0] } )[0..1];
46 0 my $channel = ${ $_[1] }->[0];
47 0 my $what = ${ $_[2] };
48 0 my $mapping = $irc->isupport('CASEMAPPING');
49 0 my $mynick = $irc->nick_name();
50 0 my ($command) = $what =~ m/^\s*\Q$mynick\E[\:\,\;\.]?\s*(.*)$/i;
51 0 ▶ return PCI_EAT_NONE unless $command;
Branch: 1 branch
BranchTrueFalseTotal
unless $command 0 0 0
52 0 my @cmd = split /\s+/, $command;
53 0 ▶ return PCI_EAT_NONE unless uc( $cmd[0] ) eq 'POEKNEE';
Branch: 1 branch
BranchTrueFalseTotal
unless uc $cmd[0] eq "POEKNEE" 0 0 0
54 0 ▶ if ( $self->{_race_in_progress} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_race_in_progress"}) 0 0 0
55 0 $irc->yield( privmsg => $channel => "There is already a race in progress" );
56 0 return PCI_EAT_NONE;
57 }
58 0 $poe_kernel->post( $self->{session_id}, '_race_on', $channel, $cmd[1] );
59 0 return PCI_EAT_NONE;
60 }
61  
62 sub _start {
63 1 ▶ my ($kernel,$self) = @_[KERNEL,OBJECT];
Subroutine _start: called CC=1 SCAR=0.0
64 1 $self->{_race_in_progress} = 0;
65 1 $self->{session_id} = $_[SESSION]->ID();
66 1 $kernel->refcount_increment( $self->{session_id}, __PACKAGE__ );
67 1 undef;
68 }
69  
70 sub _shutdown {
71 1 ▶ my ($kernel,$self) = @_[KERNEL,OBJECT];
Subroutine _shutdown: called CC=1 SCAR=0.0
72 1 $kernel->alarm_remove_all();
73 1 $kernel->refcount_decrement( $self->{session_id}, __PACKAGE__ );
74 1 undef;
75 }
76  
77 sub _race_on {
78 0 ▶ my ($kernel,$self,$channel,$stages) = @_[KERNEL,OBJECT,ARG0,ARG1];
Subroutine _race_on: not called CC=5 SCAR=34.0
79 0 ▶ $stages = $self->{stages} unless $stages and $stages =~ /^\d+$/ and $stages <= 30;
Branch: 1 branch
BranchTrueFalseTotal
unless $stages and $stages =~ /^\d+$/ and $stages <= 30 0 0 0
Condition0%0/6
$stages and $stages =~ /^\d+$/ and $stages <= 30
!ll&&!rl&&r
000
$stages and $stages =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/3
$stages and $stages =~ /^\d+$/ and $stages <= 30
$stages $stages =~ /^\d+$/ $stages <= 30
Truth table0%0/4
A and B and C
A= $stagesB= $stages =~ /^\d+$/C= $stages <= 30
ABCresult
0XX0
10X0
1100
1111
80 0 $self->{_race_in_progress} = 1;
81 0 $self->{_distance} = $stages;
82 0 $self->{_progress} = [ ];
83 0 my $irc = $self->{irc};
84 0 my @channel_list = $irc->channel_list($channel);
85 0 my $seed = 5;
86 0 my $start = 'POE::Knee Race is on! ' . scalar @channel_list . ' ponies over ' . $self->{_distance} . ' stages.';
87 0 push @{ $self->{_progress} }, join(' ', _stamp(), $start);
88 0 $irc->yield('ctcp', $channel, 'ACTION ' . $start );
89 0 foreach my $nick ( @channel_list ) {
90 #my $nick_modes = $irc->nick_channel_modes($channel,$nick);
91 #$seed += rand(3) if $nick_modes =~ /o/;
92 #$seed += rand(2) if $nick_modes =~ /h/;
93 #$seed += rand(1) if $nick_modes =~ /v/;
94 0 my $delay = random_uniform(1,0,$seed);
95 0 push @{ $self->{_progress} }, join(' ', _stamp(), $nick, "($delay)", "is off!");
96 0 $kernel->delay_add( '_run', $delay, $nick, $channel, $seed, 1 );
97 }
98 0 undef;
99 }
100  
101 sub _run {
102 0 ▶ my ($kernel,$self,$nick,$channel,$seed,$stage) = @_[KERNEL,OBJECT,ARG0..ARG3];
Subroutine _run: not called CC=3 SCAR=24.8
103 0 push @{ $self->{_progress} }, _stamp() . " $nick reached stage " . ++$stage;
104 0 ▶ if ( $stage > $self->{_distance} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stage > $self->{"_distance"}) 0 0 0
105 # Stop the race
106 0 $kernel->alarm_remove_all();
107 0 my $result = "$nick! Won the POE::Knee race!";
108 0 $self->{irc}->yield( 'privmsg', $channel, $result );
109 0 push @{ $self->{_progress} }, _stamp() . " " . $result;
110 0 my $race_result = delete $self->{_progress};
111 0 $self->{irc}->yield( '__send_event', 'irc_poeknee_results', $channel, $race_result );
112 0 $self->{_race_in_progress} = 0;
113 0 return;
114 }
115 0 ▶ if ( $stage > $self->{_race_in_progress} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stage > $self->{"_race_in_progress"}) 0 0 0
116 0 $self->{irc}->yield( 'ctcp', $channel, "ACTION $nick! leads at stage $stage" );
117 0 $self->{_race_in_progress}++;
118 }
119 0 $kernel->delay_add( '_run', random_uniform(1,0,$seed), $nick, $channel, $seed, $stage );
120 0 undef;
121 }
122  
123 sub _stamp {
124 0 ▶ return join('.', gettimeofday);
Subroutine _stamp: not called CC=1 SCAR=6.9
125 }
126  
127 2 1;
128 __END__
↑ Summary