| 1 | package POE::Component::IRC::Plugin::WWW::KrispyKreme::HotLight; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008_005; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use WWW::KrispyKreme::HotLight; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use IRC::Utils qw(parse_user); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp::POE qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use POE::Component::IRC::Plugin qw( :ALL ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | our @channels; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 16 | croak 'must supply geo as array ref i.e. ->new(geo => [35.045556,-85.267222])' | ||||||||||||||||||||||||||||||||||||||||||
| 17 | unless $args{geo} | ||||||||||||||||||||||||||||||||||||||||||
| 18 | and ref $args{geo} | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | and ref $args{geo} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$args{"geo"} and ref $args{"geo"} and ref $args{"geo"} eq "ARRAY"
$args{"geo"} and ref $args{"geo"}
MC/DC0%0/3
$args{"geo"} and ref $args{"geo"} and ref $args{"geo"} eq "ARRAY"
$args{"geo"}
ref $args{"geo"}
ref $args{"geo"} eq "ARRAY"
Truth table25%1/4
A and B and C
A= $args{"geo"}B= ref $args{"geo"}C= ref $args{"geo"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | $args{ping} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | return bless \%args, $class; | |||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | # list events we are interested in | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub PCI_register { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PCI_register: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | $irc->plugin_register($self, 'SERVER', qw(join ping)); | |||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # This is method is mandatory but we don't actually have anything to do. | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub PCI_unregister { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PCI_unregister: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | # trigger a donut search when: | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # -we join a channel | ||||||||||||||||||||||||||||||||||||||||||
| 38 | # -we are pinged by the server (every 20 times) | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub S_join { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
S_join: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $joiner = parse_user(${$_[0]}); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $nick = $irc->{nick}; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $channel = ${$_[1]}; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | push @channels, $channel; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | return $joiner eq $nick ? $self->_donuts($channel, $irc) : PCI_EAT_NONE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub S_ping { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
S_ping: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $self->{ping}++; | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | # ping interval on freenode is ~2 mins | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $ready = $self->{ping} % 20 == 0; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | return PCI_EAT_NONE unless @channels and $ready; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@channels and $ready
MC/DC0%0/2
@channels and $ready
@channels
$ready
Truth table0%0/3
A and B
A= @channelsB= $ready
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | return $self->_donuts($_, $irc) for @channels; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub _donuts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_donuts: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my ($self, $channel, $irc) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $donuts = WWW::KrispyKreme::HotLight->new(where => $self->{geo})->locations; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my $stores = join ', ', map $_->{title}, grep $_->{hotLightOn}, @$donuts; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | $irc->yield( # | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | privmsg => $channel => | ||||||||||||||||||||||||||||||||||||||||||
| 66 | "Fresh donuts available at the following Kripsy Kreme locations: $stores" | ||||||||||||||||||||||||||||||||||||||||||
| 67 | ) if $stores; | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | return PCI_EAT_PLUGIN; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||||||||||||||||