Many/Response.pm

filter: Statementstmt 24.2% 8 / 33 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 22.2% 2 / 9 Podpod 100% 7 / 7 totaltotal 29.3% 17 / 58 CC 4 SCAR 16.1
CC
4
Cov
20%
add_response
12.0
get_responses
6.0
new
2.0
CRAP 5.0
« Many/Scheduler/Selective.pm ↑ Summary Many/Scheduler/UniquenessScheduler/WeightedRandom.pm »
1 package Geo::Coder::Many::Response;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.01';
7  
8 =head1 NAME
9  
10 Geo::Coder::Many::Response - standard geocoder response container object
11  
12 =head1 DESCRIPTION
13  
14 This module provides a standard response format for geocoder results - the
15 various geocoder plugins should all do the necessary conversions to return a
16 response in this format.
17  
18 =head1 METHODS
19  
20 =head2 new
21  
22 Constructs and returns a new, empty response object.
23  
24 =cut
25  
26 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
27 0 my $class = shift;
28 0 my $args = shift;
29  
30 my $self = {
31 location => $args->{location},
32 0 responses => [],
33 response_code => 401,
34 geocoder => undef,
35 };
36  
37 0 bless $self, $class;
38  
39 0 return $self;
40 }
41  
42 =head2 add_response
43  
44 Takes a response, together with the name of the geocoder used to produce it,
45 and stores it.
46  
47 =cut
48  
49 0 ▶sub add_response {
Subroutine add_response: not called CC=3 SCAR=24.8
Pod documented
50 0 my $self = shift;
51 0 my $response = shift;
52 0 my $geocoder = shift;
53  
54 0 $self->{geocoder} = $geocoder;
55  
56 0 ▶ if ( $response->{longitude} && $response->{latitude} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"longitude"} and $response->{"latitude"}) 0 0 0
Condition0%0/3
$response->{"longitude"} and $response->{"latitude"}
!ll&&!rl&&r
000
MC/DC0%0/2
$response->{"longitude"} and $response->{"latitude"}
$response->{"longitude"} $response->{"latitude"}
Truth table0%0/3
A and B
A= $response->{"longitude"}B= $response->{"latitude"}
ABresult
0X0
100
111
57 0 push @{$self->{responses}}, $response;
58 0 $self->{response_code} = 200;
59 0 return 1;
60 }
61 0 return 0;
62 }
63  
64 =head2 set_response_code
65  
66 =cut
67  
68 0 ▶sub set_response_code {
Subroutine set_response_code: not called CC=1 SCAR=6.9
Pod documented
69 0 my $self = shift;
70 0 my $response_code = shift;
71 0 $self->{response_code} = $response_code;
72 0 return $response_code;
73 }
74  
75 =head2 get_location
76
77 Getter for the location string
78  
79 =cut
80  
81 0 ▶sub get_location { return shift->{location}; }
Subroutine get_location: not called CC=1 SCAR=6.9
Pod documented
82  
83 =head2 get_response_code
84  
85 Getter for the response code
86  
87 =cut
88  
89 0 ▶sub get_response_code { return shift->{response_code}; }
Subroutine get_response_code: not called CC=1 SCAR=6.9
Pod documented
90  
91 =head2 get_geocoder
92  
93 Getter for the geocoder name
94  
95 =cut
96  
97 0 ▶sub get_geocoder { return shift->{geocoder}; }
Subroutine get_geocoder: not called CC=1 SCAR=6.9
Pod documented
98  
99 =head2 get_responses
100  
101 In list context, returns all of the responses. In scalar context, returns the
102 first response.
103  
104 =cut
105  
106 0 ▶sub get_responses {
Subroutine get_responses: not called CC=2 SCAR=17.9
Pod documented
107 0 my $self = shift;
108 0 ▶ return wantarray ? @{$self->{responses}} : $self->{responses}->[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
109 }
110  
111 1 1;
« Many/Scheduler/Selective.pm ↑ Summary Many/Scheduler/UniquenessScheduler/WeightedRandom.pm »