| 1 | package POE::Component::IRC::Plugin::POE::Knee; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | $POE::Component::IRC::Plugin::POE::Knee::VERSION = '1.12'; | |||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=18.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | my $package = shift; | |||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
$args{"stages"} and $args{"stages"} =~ /^\d+$/ and $args{"stages"} <= 30
$args{"stages"} and $args{"stages"} =~ /^\d+$/
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
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | bless \%args, $package; | |||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | sub PCI_register { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PCI_register: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | my ($self,$irc) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | die "This plugin must be used with POE::Component::IRC::State or a subclass of that\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | sub PCI_unregister { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PCI_unregister: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | my ($self,$irc) = splice @_, 0, 2; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | $poe_kernel->call( $self->{session_id} => '_shutdown' ); | |||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | delete $self->{irc}; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub S_public { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
S_public: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my ($self,$irc) = splice @_, 0, 2; | |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my @cmd = split /\s+/, $command; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | return PCI_EAT_NONE unless uc( $cmd[0] ) eq 'POEKNEE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ( $self->{_race_in_progress} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | sub _start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_start: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | my ($kernel,$self) = @_[KERNEL,OBJECT]; | |||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | sub _shutdown { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_shutdown: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | my ($kernel,$self) = @_[KERNEL,OBJECT]; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | $kernel->alarm_remove_all(); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | $kernel->refcount_decrement( $self->{session_id}, __PACKAGE__ ); | |||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | undef; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub _race_on { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_race_on: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my ($kernel,$self,$channel,$stages) = @_[KERNEL,OBJECT,ARG0,ARG1]; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $stages = $self->{stages} unless $stages and $stages =~ /^\d+$/ and $stages <= 30; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$stages and $stages =~ /^\d+$/ and $stages <= 30
$stages and $stages =~ /^\d+$/
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub _run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my ($kernel,$self,$nick,$channel,$seed,$stage) = @_[KERNEL,OBJECT,ARG0..ARG3]; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | push @{ $self->{_progress} }, _stamp() . " $nick reached stage " . ++$stage; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ( $stage > $self->{_distance} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub _stamp { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stamp: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | return join('.', gettimeofday); | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | qq[Ride the ponies]; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | __END__ | ||||||||||||||||||||||||||||||||||||||||||