Google/Path.pm

filter: Statementstmt 20.4% 20 / 98 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 37.5% 6 / 16 Podpod 0.0% 0 / 10 totaltotal 17.8% 26 / 146 CC 14 SCAR 41.9
CC
14
Cov
17%
toJSON
156.0
segments
6.0
locations
6.0
CRAP 66.1
« Google.pm ↑ Summary Google/Segment.pm »
1 package Geo::Google::Path;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Geo::Google;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 our $VERSION = '0.04-rc3';
8  
9 1 ▶use constant FMT => <<_FMT_;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 <segments distance="%s" time="%s">
11 %s</segments>
12 _FMT_
13  
14 #<segments distance="0.6&#160;mi" meters="865" seconds="56" time="56 secs">
15 # <segment distance="0.4&#160;mi" id="seg0" meters="593" pointIndex="0" seconds="38" time="38 secs">Head <b>southwest</b> from <b>Venice Blvd</b></segment>
16 # <segment distance="0.2&#160;mi" id="seg1" meters="272" pointIndex="6" seconds="18" time="18 secs">Make a <b>U-turn</b> at <b>Venice Blvd</b></segment>
17 #</segments>
18  
19 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
20 0 my $class = shift;
21 0 my %arg = @_;
22 0 my $self = bless \%arg, $class;
23 }
24  
25 0 ▶sub distance { return shift->{'distance'} }
Subroutine distance: not called CC=1 SCAR=6.9
Pod undocumented
26 0 ▶sub polyline { return shift->{'polyline'} }
Subroutine polyline: not called CC=1 SCAR=6.9
Pod undocumented
27 0 ▶sub segments { my $self = shift; return $self->{'segments'} ? @{ $self->{'segments'} } : () }
Subroutine segments: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$self->{'segments'} ? : 0 0 0
28 0 ▶sub time { return shift->{'time'} }
Subroutine time: not called CC=1 SCAR=6.9
Pod undocumented
29 0 ▶sub locations { my $self = shift; return $self->{'locations'} ? @{ $self->{'locations'} } : () }
Subroutine locations: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$self->{'locations'} ? : 0 0 0
30 0 ▶sub panel { return shift->{'panel'} }
Subroutine panel: not called CC=1 SCAR=6.9
Pod undocumented
31 0 ▶sub levels { return shift->{'levels'} }
Subroutine levels: not called CC=1 SCAR=6.9
Pod undocumented
32  
33 0 ▶sub toXML {
Subroutine toXML: not called CC=1 SCAR=6.9
Pod undocumented
34 0 my $self = shift;
35 0 my $content = join "", map { $_->toXML } @{ $self->{segments} };
36 0 return sprintf( FMT,
37 $self->distance(),
38 $self->time(),
39 $content,
40 );
41 }
42  
43 0 ▶sub toJSON {
Subroutine toJSON: not called CC=12 SCAR=50.5
Pod undocumented
44 0 my $self = shift;
45 0 my $json = new JSON (barekey => 1);
46  
47 # Construct the shell of a new perl data structure that we
48 # can pass off to the JSON module for rendering to a string
49 0 my $preJSON = Geo::Google::_JSONrenderSkeleton();
50  
51 # Fill the perl data structure with information from this
52 # location
53 0 my @locations = $self->locations();
54 0 $preJSON->{"form"}->{"l"}->{"near"} =
55 $locations[$#locations]->title();
56 0 $preJSON->{"form"}->{"q"}->{"q"} = "from:" .
57 $locations[0]->title();
58 0 ▶ for (my $i=1; $i<=$#locations; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#locations) 0 0 0
59 0 $preJSON->{"form"}->{"q"}->{"q"} .= " to:" .
60 $locations[$i]->title();
61 }
62 0 $preJSON->{"form"}->{"d"}->{"saddr"} = $locations[0]->title();
63 0 $preJSON->{"form"}->{"d"}->{"daddr"} = $locations[1]->title();
64 0 ▶ for (my $i=2; $i<=$#locations; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#locations) 0 0 0
65 0 $preJSON->{"form"}->{"d"}->{"daddr"} .= " to:" .
66 $locations[$i]->title();
67 }
68 0 $preJSON->{"form"}->{"selected"} = "q";
69 0 $preJSON->{"panelStyle"} = "";
70 # Generate the markers
71 0 ▶ for (my $i=0; $i<=$#locations; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#locations) 0 0 0
72 0 my $image = "/mapfiles/dd-pause.png";
73 0 my $id = "pause";
74 0 ▶ if ($i == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i == 0) { } 0 0 0
elsif ($i == $#locations) { } 0 0 0
75 0 $image = "/mapfiles/dd-start.png";
76 0 $id = "start";
77 }
78 elsif ($i == $#locations) {
79 0 $image = "/mapfiles/dd-stop.png";
80 0 $id = "stop";
81 }
82 0 push( @{$preJSON->{"overlays"}->{"markers"}}, {
83 "laddr" => "",
84 "svaddr" => "",
85 "lat" => $locations[$i]->latitude(),
86 "lng" => $locations[$i]->longitude(),
87 "id" => $id,
88 "image" => $image,
89 "elms" => [()],
90 "llcid" => "",
91 "fid" => "",
92 "cid" => "",
93 "sig" => "",
94 "infoWindow" => {
95 "type" => "map",
96 "_" => 0
97 }
98 });
99 }
100 0 $preJSON->{"overlays"}->{"polylines"}->[0]->{"levels"} =
101 $self->levels();
102 0 $preJSON->{"overlays"}->{"polylines"}->[0]->{"points"} =
103 $self->polyline();
104 0 $preJSON->{"overlays"}->{"polylines"}->[0]->{"outline"} = undef;
105 0 $preJSON->{"overlays"}->{"polylines"}->[0]->{"opacity"} = undef;
106 0 $preJSON->{"overlays"}->{"polylines"}->[0]->{"color"} = undef;
107 0 $preJSON->{"overlays"}->{"polylines"}->[0]->{"weight"} = undef;
108 0 $preJSON->{"overlays"}->{"polylines"}->[0]->{"id"} = "d";
109 0 $preJSON->{"overlays"}->{"polylines"}->[0]->{"numLevels"} = 4;
110 0 $preJSON->{"overlays"}->{"polylines"}->[0]->{"zoomFactor"} = 16;
111 0 $preJSON->{"printheader"} = sprintf("Directions from %s to %s"
112 . "<BR />Travel time: %s",
113 $locations[0]->title(),
114 $locations[$#locations]->title(),
115 $self->time());
116 0 $preJSON->{"modules"} = [(undef, "multiroute")];
117 0 $preJSON->{"panelResizeState"} = "open";
118 # step through all points in the directions and determine
119 # the maximum and minimum lat/longs
120 0 my $maxlat = -90;
121 0 my $minlat = 90;
122 0 my $maxlng = -180;
123 0 my $minlng = 180;
124 0 foreach my $segment ($self->segments()) {
125 0 foreach my $point ($segment->points()) {
126 0 ▶ if ($point->latitude() > $maxlat)
Branch: 1 branch
BranchTrueFalseTotal
if ($point->latitude > $maxlat) 0 0 0
127 0 { $maxlat = $point->latitude(); }
128 0 ▶ if ($point->latitude() < $minlat)
Branch: 1 branch
BranchTrueFalseTotal
if ($point->latitude < $minlat) 0 0 0
129 0 { $minlat = $point->latitude(); }
130 0 ▶ if ($point->longitude() > $maxlng)
Branch: 1 branch
BranchTrueFalseTotal
if ($point->longitude > $maxlng) 0 0 0
131 0 { $maxlng = $point->longitude(); }
132 0 ▶ if ($point->longitude() < $minlng)
Branch: 1 branch
BranchTrueFalseTotal
if ($point->longitude < $minlng) 0 0 0
133 0 { $minlng = $point->longitude(); }
134 }
135 }
136 0 $preJSON->{"viewport"}->{"span"}->{"lat"} = sprintf("%.6f",
137 ( ($maxlat-$minlat) * 1.1) );
138 0 $preJSON->{"viewport"}->{"span"}->{"lng"} = sprintf("%.6f",
139 ( ($maxlng-$minlng) * 1.1) );
140 0 $preJSON->{"viewport"}->{"center"}->{"lat"} = sprintf("%.6f",
141 ( ($maxlat+$minlat) / 2) );
142 0 $preJSON->{"viewport"}->{"center"}->{"lng"} = sprintf("%.6f",
143 ( ($maxlng+$minlng) / 2) );
144 0 $preJSON->{"viewport"}->{"mapType"} = undef;
145 $preJSON->{"url"} = "/maps?v=1&q=" .
146 uri_escape(sprintf("from:%s to:%s",
147 $locations[0]->title(),
148 0 $preJSON->{"form"}->{"d"}->{"daddr"}))
149 . "&ie=UTF8";
150 $preJSON->{"title"} = sprintf("From:%s to:%s",
151 $locations[0]->title(),
152 0 $preJSON->{"form"}->{"d"}->{"daddr"});
153 0 $preJSON->{"panel"} = $self->panel();
154  
155 # Render the data structure to a JSON string and return it
156 0 return $json->objToJson($preJSON);
157 }
158  
159 1 1;
160 __END__
« Google.pm ↑ Summary Google/Segment.pm »