V2/Path.pm

filter: Statementstmt 86.8% 53 / 61 Branchbran 65.7% 25 / 38 Conditioncond 33.3% 6 / 18 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 90.9% 10 / 11 Podpod 100% 5 / 5 totaltotal 69.7% 99 / 142 CC 28 SCAR 28.1
CC
28
Cov
72%
_encode_locations
56.0
_color
13.8
_styles
6.1
CRAP 16.6
↑ Summary V2/Markers.pm »
1 package Geo::Google::StaticMaps::V2::Path;
2 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use base qw{Geo::Google::StaticMaps::V2::Visible};
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 our $VERSION = '0.12';
6 10 our $PACKAGE = __PACKAGE__;
7  
8 =head1 NAME
9  
10 Geo::Google::StaticMaps::V2::Path - Generate Images from Google Static Maps V2 API
11  
12 =head1 SYNOPSIS
13  
14 use Geo::Google::StaticMaps::V2;
15 my $map=Geo::Google::StaticMaps::V2->new;
16 my $path=$map->path(locations=>["Clifton, VA", "Pag, Croatia"], geodesic=>1); #isa Geo::Google::StaticMaps::V2::Path
17 print $map->url, "\n";
18  
19 =head1 DESCRIPTION
20  
21 The packages generates images from the Google Static Maps V2 API which can be saved locally for use in accordance with your license with Google.
22  
23 =head1 USAGE
24  
25 =head1 PROPERTIES
26  
27 =head2 encode
28  
29 encode: (optional) specifies weather or not to encode path using the Google Polyline Encoding Algorithm as implemented by L<Algorithm::GooglePolylineEncoding>. The default is to not encode (value of 0).
30  
31 my $path=$map->path(encode=>1); #on construction
32 $path->encode(1); #after construction
33  
34 Note: Encoding the path has the advantage of being able to specify large polylines on a limited URL length. The disadvantages are: 1) it limits specified locations to latitude and longitude, 2) it limits coordinate accuracy to 5 decimal places and 3) the resultant URL is not human readable.
35  
36 =cut
37  
38 24 ▶sub encode {
Subroutine encode: called CC=3 SCAR=11.0
Pod documented
39 24 my $self=shift;
40 24 ▶ $self->{'encode'}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 24 24
41 24 ▶ $self->{'encode'}=0 unless defined $self->{'encode'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"encode"} 5 19 24
42 24 return $self->{'encode'};
43 }
44  
45 24 ▶sub _styles {
Subroutine _styles: called CC=6 SCAR=18.0
46 24 my $self=shift;
47 24 my @styles=();
48 24 ▶ push @styles, join ':', weight => $self->weight if defined $self->weight;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->weight 0 24 24
49 24 ▶ push @styles, join ':', color => $self->color if defined $self->color;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->color 9 15 24
50 24 ▶ push @styles, join ':', fillcolor => $self->fillcolor if defined $self->fillcolor;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->fillcolor 11 13 24
51 24 ▶ push @styles, join ':', geodesic => $self->geodesic ? 'true' : 'false' if defined $self->geodesic;
Branch: 2 branches
BranchTrueFalseTotal
if defined $self->geodesic 1 23 24
$self->geodesic ? : 1 0 1
52 24 return @styles;
53 }
54  
55 =head2 weight
56  
57 weight: (optional) specifies the thickness of the path in pixels. If no weight parameter is set, the path will appear in its default thickness (5 pixels).
58  
59 =cut
60  
61 24 ▶sub weight {
Subroutine weight: called CC=2 SCAR=7.1
Pod documented
62 24 my $self=shift;
63 24 ▶ $self->{'weight'}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 24 24
64 24 return $self->{'weight'};
65 }
66  
67 =head2 color
68  
69 color: (optional) specifies a color either as a 24-bit (example: color=0xFFFFCC) or 32-bit hexadecimal value (example: color=0xFFFFCCFF), or from the set {black, brown, green, purple, yellow, blue, gray, orange, red, white}.
70  
71 When a 32-bit hex value is specified, the last two characters specify the 8-bit alpha transparency value. This value varies between 00 (completely transparent) and FF (completely opaque). Note that transparencies are supported in paths, though they are not supported for markers.
72  
73 my $color=$path->color("blue");
74 my $color=$path->color("0xFFFFCC");
75 my $color=$path->color({r=>255,g=>0,b=>0,a=>64}); #maps to red 25% returns 0xFF000040
76 my $color=$path->color([0,255,0,"75%"]); #maps to green 75% returns 0x00FF00C0
77  
78 =cut
79  
80 85 ▶sub _color {
Subroutine _color: called CC=13 SCAR=26.3
81 85 my $self=shift;
82 85 my $key=shift; #color||fillcolor
83 85 ▶ $self->{$key}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 17 68 85
84 85 ▶ if (ref($self->{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{$key}) { } 30 55 85
85 30 my $r;
86 my $g;
87 30 my $b;
88 30 my $a;
89 30 ▶ if (ref($self->{$key}) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self->{$key} eq 'HASH') { } 18 12 30
elsif (ref $self->{$key} eq 'ARRAY') { } 12 0 12
90 18 ▶ $r = $self->{$key}->{'r'} || 0;
Condition50%1/2
$self->{$key}{'r'} || 0
l!l
180
MC/DC0%0/1
$self->{$key}{'r'} || 0
$self->{$key}{'r'}
Truth table50%1/2
A
A= $self->{$key}{'r'}
Aresult
11
00
91 18 ▶ $g = $self->{$key}->{'g'} || 0;
Condition50%1/2
$self->{$key}{'g'} || 0
l!l
018
MC/DC0%0/1
$self->{$key}{'g'} || 0
$self->{$key}{'g'}
Truth table50%1/2
A
A= $self->{$key}{'g'}
Aresult
11
00
92 18 ▶ $b = $self->{$key}->{'b'} || 0;
Condition50%1/2
$self->{$key}{'b'} || 0
l!l
018
MC/DC0%0/1
$self->{$key}{'b'} || 0
$self->{$key}{'b'}
Truth table50%1/2
A
A= $self->{$key}{'b'}
Aresult
11
00
93 18 $a = $self->{$key}->{'a'};
94 } elsif (ref($self->{$key}) eq 'ARRAY') {
95 12 ▶ $r = $self->{$key}->[0] || 0;
Condition50%1/2
$self->{$key}[0] || 0
l!l
120
MC/DC0%0/1
$self->{$key}[0] || 0
$self->{$key}[0]
Truth table50%1/2
A
A= $self->{$key}[0]
Aresult
11
00
96 12 ▶ $g = $self->{$key}->[1] || 0;
Condition50%1/2
$self->{$key}[1] || 0
l!l
012
MC/DC0%0/1
$self->{$key}[1] || 0
$self->{$key}[1]
Truth table50%1/2
A
A= $self->{$key}[1]
Aresult
11
00
97 12 ▶ $b = $self->{$key}->[2] || 0;
Condition50%1/2
$self->{$key}[2] || 0
l!l
012
MC/DC0%0/1
$self->{$key}[2] || 0
$self->{$key}[2]
Truth table50%1/2
A
A= $self->{$key}[2]
Aresult
11
00
98 12 $a = $self->{$key}->[3];
99 } else {
100 0 die('Error: Unknown reference type expecting HASH or ARRAY.');
101 }
102 30 ▶ if (defined $a) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $a) { } 24 6 30
103 24 ▶ if ($a =~ m/^(100|\d\d|\d)\%$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a =~ /^(100|\d\d|\d)\%$/) 12 12 24
104 12 $a=int($1/100*255);
105 }
106 24 return sprintf("0x%02X%02X%02X%02X", $r, $g, $b, $a);
107 } else {
108 6 return sprintf("0x%02X%02X%02X", $r, $g, $b);
109 }
110 } else {
111 55 return $self->{$key};
112 }
113 }
114  
115 41 ▶sub color {shift->_color(color=>@_)};
Subroutine color: called CC=1 SCAR=0.0
Pod documented
116  
117 =head2 fillcolor
118  
119 fillcolor: (optional) indicates both that the path marks off a polygonal area and specifies the fill color to use as an overlay within that area. The set of locations following need not be a "closed" loop; the Static Map server will automatically join the first and last points. Note, however, that any stroke on the exterior of the filled area will not be closed unless you specifically provide the same beginning and end location.
120  
121 =cut
122  
123 44 ▶sub fillcolor {shift->_color(fillcolor=>@_)};
Subroutine fillcolor: called CC=1 SCAR=0.0
Pod documented
124  
125 =head2 geodesic
126  
127 geodesic: (optional) indicates that the requested path should be interpreted as a geodesic line that follows the curvature of the Earth. When false, the path is rendered as a straight line in screen space. Defaults to false.
128  
129 =cut
130  
131 26 ▶sub geodesic {
Subroutine geodesic: called CC=2 SCAR=6.9
Pod documented
132 26 my $self=shift;
133 26 ▶ $self->{'geodesic'}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 25 26
134 26 return $self->{'geodesic'};
135 }
136  
137 =head1 METHODS
138  
139 =head2 addLocation
140  
141 $marker->addLocation("Clifton, VA");
142  
143 =cut
144  
145 0 ▶sub _encode_locations {
Subroutine _encode_locations: not called CC=7 SCAR=40.3
146 0 my $self=shift;
147 0 eval 'use Algorithm::GooglePolylineEncoding'; #run time requirment
148 0 my $error=$@;
149 0 ▶ die('Error: option encode was enabled but Algorithm::GooglePolylineEncoding pacakge would not load. \n$error') if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
150 my @points=map {
151 0 ▶ ref($_) eq 'HASH' ? $_ :
Branch: 3 branches
BranchTrueFalseTotal
ref $_ eq 'HASH' ? : 0 0 0
ref $_ eq 'ARRAY' ? : 0 0 0
ref $_ && $_->can('lat') && $_->can('lon') ? : 0 0 0
Condition0%0/6
ref $_ and $_->can("lat") and $_->can("lon")
!ll&&!rl&&r
000
ref $_ and $_->can("lat")
!ll&&!rl&&r
000
MC/DC0%0/3
ref $_ and $_->can("lat") and $_->can("lon")
ref $_ $_->can("lat") $_->can("lon")
Truth table0%0/4
A and B and C
A= ref $_B= $_->can("lat")C= $_->can("lon")
ABCresult
0XX0
10X0
1100
1111
152 ref($_) eq 'ARRAY' ? {lat=>$_->[0], lon=>$_->[1]} :
153 ref($_) && $_->can("lat") && $_->can("lon") ? {lat=>$_->lat, lon=>$_->lon} :
154 die('Error: Stringifacation with the encode option only supports locations as coordinate pairs in hashes, arrays or object than have lat and lon methods')
155 } $self->locations;
156 0 return 'enc:'. Algorithm::GooglePolylineEncoding::encode_polyline(@points); #@points=({lat=>38, lon=>-77}, ...);
157 }
158  
159 =head1 BUGS
160  
161 Please log on RT and send an email to the author.
162  
163 =head1 SUPPORT
164  
165 DavisNetworks.com supports all Perl applications including this package.
166  
167 =head1 AUTHOR
168  
169 Michael R. Davis
170 CPAN ID: MRDVT
171 Satellite Tracking of People, LLC
172 mdavis@stopllc.com
173 http://www.stopllc.com/
174  
175 =head1 COPYRIGHT
176  
177 This program is free software licensed under the...
178  
179 The General Public License (GPL) Version 2, June 1991
180  
181 The full text of the license can be found in the LICENSE file included with this module.
182  
183 =head1 SEE ALSO
184  
185 L<Geo::Google::StaticMaps::V2>
186  
187 =cut
188  
189 10 1;
↑ Summary V2/Markers.pm »