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

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