blib/lib/POE/Component/IRC/Plugin/WWW/KrispyKreme/HotLight.pm

filter: Statementstmt 48.8% 21 / 43 Branchbran 12.5% 1 / 8 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 54.5% 6 / 11 Podpod 0.0% 0 / 5 totaltotal 37.0% 30 / 81 CC 9 SCAR 19.5
CC
9
Cov
40%
S_ping
20.0
S_join
6.0
_donuts
6.0
CRAP 7.0
↑ Summary
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
BranchTrueFalseTotal
unless $args{"geo"} and ref $args{"geo"} and ref $args{"geo"} eq "ARRAY" 0 1 1
Condition33%2/6
$args{"geo"} and ref $args{"geo"} and ref $args{"geo"} eq "ARRAY"
!ll&&!rl&&r
001
$args{"geo"} and ref $args{"geo"}
!ll&&!rl&&r
001
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"
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
$joiner eq $nick ? : 0 0 0
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
BranchTrueFalseTotal
unless @channels and $ready 0 0 0
Condition0%0/3
@channels and $ready
!ll&&!rl&&r
000
MC/DC0%0/2
@channels and $ready
@channels $ready
Truth table0%0/3
A and B
A= @channelsB= $ready
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $stores 0 0 0
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__
↑ Summary