File Coverage

blib/lib/WWW/KrispyKreme/HotLight.pm
Criterion Covered Total %
statement 17 17 100.0
branch 2 4 50.0
condition 2 6 33.3
subroutine 3 3 100.0
pod n/a
total 24 30 80.0


line stmt bran cond sub pod time code
1             package WWW::KrispyKreme::HotLight;
2              
3 1     1   53761 use Mojo::Base -base;
  1         14151  
  1         10  
4 1     1   1328 use Mojo::UserAgent;
  1         478617  
  1         16  
5              
6             our $VERSION = '0.06';
7              
8             has 'where';
9              
10             has locations => \&_build_locations;
11              
12             sub _build_locations {
13 1     1   1074 my ($self) = @_;
14 1 50       29 my $geo = $self->where or return [];
15              
16 1         23 my $ua = Mojo::UserAgent->new;
17 1         8 my $base_url = 'http://locations.krispykreme.com/Store-Locator/';
18 1         2 my $hotlight_url = 'http://locations.krispykreme.com/Hotlight/HotLightStatus.ashx';
19 1         5 my $header = {'X-Requested-With' => 'XMLHttpRequest'};
20 1         6 my $form = {lat => $geo->[0], lng => $geo->[1]};
21              
22 1         8 my $locations = join ',',
23             $ua->get($base_url => $header => form => $form)
24             ->res->dom->find('.content-results')->attr('id')->each;
25              
26 1   33     1637720 my $json = $locations && $ua->post(
27             $hotlight_url => {%$header, Referer => $base_url}
28             => form => {locations => $locations}
29             )->res->json;
30              
31 1         18 return $json && $json->{status} eq 'success'
32 1 50 33     108846 ? [@{$json->{data}{locations}}]
33             : [];
34             }
35              
36             1;
37             __END__