Geocodio/Request.pm

filter: Statementstmt 55.3% 26 / 47 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 58.3% 7 / 12 Podpod 100% 2 / 2 totaltotal 53.8% 35 / 65 CC 3 SCAR 12.9
CC
3
Cov
51%
_request
12.0
__ANON__
2.0
__ANON__
2.0
CRAP 3.6
« Geocodio.pm ↑ Summary Geocodio/JSON.pm »
1 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package WebService::Geocodio::Request;
5 6 $WebService::Geocodio::Request::VERSION = '0.05';
6 6 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use WebService::Geocodio::Location;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 with 'WebService::Geocodio::JSON';
13  
14 # ABSTRACT: A request role for Geocod.io
15  
16  
17 has 'ua' => (
18 is => 'ro',
19 lazy => 1,
20 0 ▶ default => sub { HTTP::Tiny->new(
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 agent => "WebService-Geocodio ",
22 default_headers => { 'Content-Type' => 'application/json' },
23 ) },
24 6 );
25  
26  
27 has 'base_url' => (
28 is => 'ro',
29 lazy => 1,
30 0 ▶ default => sub { 'http://api.geocod.io/v1.2/' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 6 );
32  
33  
34 0 ▶sub send_forward {
Subroutine send_forward: not called CC=1 SCAR=6.9
Pod documented
35 0 my $self = shift;
36  
37 0 $self->_request('geocode', $self->encode(@_));
38 }
39  
40  
41 0 ▶sub send_reverse {
Subroutine send_reverse: not called CC=1 SCAR=6.9
Pod documented
42 0 my $self = shift;
43  
44 0 $self->_request('reverse', $self->encode(@_));
45 }
46  
47 0 ▶sub _request {
Subroutine _request: not called CC=3 SCAR=24.8
48 0 my ($self, $op, $content) = @_;
49  
50 0 my $url;
51 0 ▶ if ( $self->has_fields ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_fields) { } 0 0 0
52 $url = $self->base_url
53 0 . "$op?fields=" . join(',', @{ $self->fields })
54 . "&api_key=" . $self->api_key
55 ;
56 }
57 else {
58 0 $url = $self->base_url . "$op?api_key=" . $self->api_key;
59 }
60  
61 0 my $response = $self->ua->request('POST', $url, { content => $content });
62  
63 0 ▶ if ( $response->{success} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{'success'}) { } 0 0 0
64 0 my $hr = $self->decode($response->{content});
65 0 return map { WebService::Geocodio::Location->new($_) }
66 0 map {; @{$_->{response}->{results}} } @{$hr->{results}};
67 }
68 else {
69 confess "Request to " . $self->base_url . "$op failed: (" .
70 0 $response->{status} . ") - " . $response->{content};
71 }
72 }
73  
74  
75 6 1;
76  
77 __END__
« Geocodio.pm ↑ Summary Geocodio/JSON.pm »