Pluggable/Placemark.pm

filter: Statementstmt 51.8% 42 / 81 Branchbran 23.6% 9 / 38 Conditioncond 7.8% 3 / 38 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 66.6% 10 / 15 Podpod 100% 10 / 10 totaltotal 36.8% 74 / 201 CC 35 SCAR 51.6
CC
35
Cov
34%
point_normalize
420.0
node
8.1
styleUrl
6.3
CRAP 174.3
« Pluggable/Style.pm ↑ Summary Pluggable/StyleMap.pm »
1 package Geo::GoogleEarth::Pluggable::Placemark;
2 3 ▶use base qw{Geo::GoogleEarth::Pluggable::Base};
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Scalar::Util qw{reftype blessed};
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use XML::LibXML::LazyBuilder qw{E};
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 our $VERSION='0.14';
9  
10 =head1 NAME
11  
12 Geo::GoogleEarth::Pluggable::Placemark - Base Object for Geo::GoogleEarth::Pluggable Placemarks
13  
14 =head1 SYNOPSIS
15  
16 use base qw{Geo::GoogleEarth::Pluggable::Placemark};
17  
18 =head1 DESCRIPTION
19  
20 The is the base of all Geo::GoogleEarth::Pluggable packages.
21  
22 =head1 USAGE
23  
24 =head1 METHODS
25  
26 =head2 type
27  
28 =cut
29  
30 9 ▶sub type {"Placemark"};
Subroutine type: called CC=1 SCAR=0.0
Pod documented
31  
32 =head2 style
33  
34 Sets or returns the Placemark Style or StyleMap object.
35  
36 style=>$style is a short cut for styleUrl=>$style->url
37  
38 =cut
39  
40 sub style {
41 3 ▶ my $self=shift;
Subroutine style: called CC=2 SCAR=7.1
Pod documented
42 3 ▶ $self->{"style"}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 3 3
43 3 return $self->{"style"};
44 }
45  
46 =head2 styleUrl
47  
48 This overrides style->url if defined.
49  
50 =cut
51  
52 sub styleUrl {
53 3 ▶ my $self=shift;
Subroutine styleUrl: called CC=5 SCAR=18.4
Pod documented
54 3 my $url=undef;
55 3 ▶ $url=$self->style->url if blessed($self->style) && $self->style->can("url");
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($self->style) and $self->style->can("url") 0 3 3
Condition33%1/3
builtin::blessed($self->style) and $self->style->can("url")
!ll&&!rl&&r
300
MC/DC0%0/2
builtin::blessed($self->style) and $self->style->can("url")
builtin::blessed($self->style) $self->style->can("url")
Truth table33%1/3
A and B
A= builtin::blessed($self->style)B= $self->style->can("url")
ABresult
0X0
100
111
56 3 ▶ $self->{"styleUrl"}||=$url;
Condition33%1/3
$self->{"styleUrl"} ||= $url
l!l&&r!l&&!r
003
MC/DC0%0/2
$self->{"styleUrl"} ||= $url
$self->{"styleUrl"} $url
Truth table33%1/3
A ||= B
A= $self->{"styleUrl"}B= $url
ABresult
1X1
011
000
57 3 ▶ $self->{"styleUrl"}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 3 3
58 3 return $self->{"styleUrl"};
59 }
60  
61 =head2 LookAt
62  
63 Sets or returns the LookAt Object
64  
65 =cut
66  
67 sub LookAt {
68 0 ▶ my $self=shift;
Subroutine LookAt: not called CC=2 SCAR=17.9
Pod documented
69 0 ▶ $self->{"LookAt"}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
70 0 return $self->{"LookAt"};
71 }
72  
73 =head2 visibility
74  
75 Sets or returns visibility. The value is either 1 or 0 but defaults to undef which the same as 1.
76  
77 my $visibility=$placemark->visibility;
78  
79 =cut
80  
81 sub visibility {
82 3 ▶ my $self=shift;
Subroutine visibility: called CC=2 SCAR=7.1
Pod documented
83 3 ▶ $self->{"visibility"}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 3 3
84 3 return $self->{"visibility"};
85 }
86  
87 =head2 node
88  
89 =cut
90  
91 sub node {
92 3 ▶ my $self=shift;
Subroutine node: called CC=7 SCAR=20.9
Pod documented
93 3 my @element=();
94 3 ▶ push @element, $self->lookat->node
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->lookat and $self->lookat->can("node") 0 3 3
Condition33%1/3
ref $self->lookat and $self->lookat->can("node")
!ll&&!rl&&r
300
MC/DC0%0/2
ref $self->lookat and $self->lookat->can("node")
ref $self->lookat $self->lookat->can("node")
Truth table33%1/3
A and B
A= ref $self->lookatB= $self->lookat->can("node")
ABresult
0X0
100
111
95 if ref($self->lookat) and $self->lookat->can("node");
96 3 ▶ push @element, E(name=>{}, $self->name)
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->name 3 0 3
97 if defined $self->name;
98 3 push @element, E(Snippet=>{maxLines=>scalar(@{$self->Snippet})}, join("\n", @{$self->Snippet}));
99 3 ▶ push @element, E(description=>{}, $self->description)
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->description 0 3 3
100 if defined $self->description;
101 3 ▶ push @element, E(visibility=>{}, $self->visibility)
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->visibility 0 3 3
102 if defined $self->visibility;
103 3 ▶ push @element, E(styleUrl=>{}, $self->styleUrl)
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->styleUrl 0 3 3
104 if defined $self->styleUrl;
105 3 push @element, $self->subnode;
106 3 return E($self->type=>{}, @element);
107 }
108  
109 =head2 coordinates
110  
111 The coordinates array is used consistantly for all placemark objects.
112  
113 my $coordinates=$placemark->coordinates(
114 [
115 [$lon, $lat, $alt],
116 {lat=>$lat, lon=>$lon, alt=>$alt},
117 GPS::Point,
118 Geo::Point,
119 Net::GPSD::Point,
120 ]
121 );
122  
123 my $coordinates=$placemark->coordinates(
124 Geo::Line, #TODO
125 );
126  
127  
128 =cut
129  
130 sub coordinates {
131 0 ▶ my $self=shift;
Subroutine coordinates: not called CC=2 SCAR=17.9
Pod documented
132 0 ▶ $self->{"coordinates"}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
133 0 return $self->{"coordinates"};
134 }
135  
136 =head2 coordinates_stringify
137  
138 =cut
139  
140 sub coordinates_stringify {
141 0 ▶ my $self=shift;
Subroutine coordinates_stringify: not called CC=2 SCAR=17.9
Pod documented
142 0 my $data=$self->coordinates;
143 0 my $string="";
144 0 ▶ if (ref($data) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data eq 'ARRAY') { } 0 0 0
145 0 $string=join(" ", map {$self->point_stringify($_)} @$data);
146 } else {
147 0 die(sprintf(qq{Error: the coordinates_stringify method does not understand coordinates value type "%s"}, ref($data)));
148 }
149 0 return $string;
150 }
151  
152 =head2 point_stringify
153  
154 my $string=$placemark->point_stringify($point); #returns "$lon,$lat,$alt"
155  
156 =cut
157  
158 sub point_stringify {
159 0 ▶ my $self=shift;
Subroutine point_stringify: not called CC=1 SCAR=6.9
Pod documented
160 0 my %data=$self->point_normalize(@_);
161 0 return join(",", @data{qw{lon lat alt}});
162 }
163  
164 =head2 point_normalize
165  
166 Most of this code was taken from GPS::Point->initializeMulti
167  
168 my $data=$placemark->point_normalize($point); #returns {lat=>$lat,lon=>$lon,alt=>$alt}
169  
170 =cut
171  
172 sub point_normalize {
173 0 ▶ my $self=shift;
Subroutine point_normalize: not called CC=20 SCAR=60.4
Pod documented
174 0 my $point=shift;
175 0 my $data={};
176 0 ▶ if (ref($point) eq "Geo::Point") {
Branch: 5 branches
BranchTrueFalseTotal
if (ref $point eq 'Geo::Point') { } 0 0 0
elsif (ref $point eq 'GPS::Point') { } 0 0 0
elsif (ref $point eq 'Net::GPSD::Point') { } 0 0 0
elsif (builtin::reftype($point) eq 'HASH') { } 0 0 0
elsif (builtin::reftype($point) eq 'ARRAY') { } 0 0 0
177 0 ▶ $point=$point->in('wgs84') unless $point->proj eq "wgs84";
Branch: 1 branch
BranchTrueFalseTotal
unless $point->proj eq "wgs84" 0 0 0
178 0 $data->{'lat'}=$point->latitude;
179 0 $data->{'lon'}=$point->longitude;
180 0 $data->{'alt'}=0;
181 } elsif (ref($point) eq "GPS::Point") {
182 0 $data->{'lat'}=$point->lat;
183 0 $data->{'lon'}=$point->lon;
184 0 ▶ $data->{'alt'}=$point->alt||0;
Condition0%0/2
$point->alt || 0
l!l
00
MC/DC0%0/1
$point->alt || 0
$point->alt
Truth table0%0/2
A
A= $point->alt
Aresult
11
00
185 } elsif (ref($point) eq "Net::GPSD::Point") {
186 0 $data->{'lat'}=$point->latitude;
187 0 $data->{'lon'}=$point->longitude;
188 0 ▶ $data->{'alt'}=$point->altitude||0;
Condition0%0/2
$point->altitude || 0
l!l
00
MC/DC0%0/1
$point->altitude || 0
$point->altitude
Truth table0%0/2
A
A= $point->altitude
Aresult
11
00
189 } elsif (reftype($point) eq "HASH") {
190 #{lat=>$lat, lon=>$lon, alt=>$alt}
191 0 ▶ $data->{'lat'}=$point->{'lat'}||$point->{'latitude'};
Condition0%0/3
$point->{'lat'} || $point->{'latitude'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$point->{'lat'} || $point->{'latitude'}
$point->{'lat'} $point->{'latitude'}
Truth table0%0/3
A || B
A= $point->{'lat'}B= $point->{'latitude'}
ABresult
1X1
011
000
192 0 ▶ $data->{'lon'}=$point->{'lon'}||$point->{'long'}||$point->{'longitude'};
Condition0%0/6
$point->{'lon'} || $point->{'long'} || $point->{'longitude'}
l!l&&r!l&&!r
000
$point->{"lon"} or $point->{"long"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$point->{'lon'} || $point->{'long'} || $point->{'longitude'}
$point->{"lon"} $point->{"long"} $point->{'longitude'}
Truth table0%0/4
A or B || C
A= $point->{"lon"}B= $point->{"long"}C= $point->{'longitude'}
ABCresult
1XX1
01X1
0011
0000
193 $data->{'alt'}=$point->{'alt'}||$point->{'altitude'}||
194 0 ▶ $point->{'elevation'}||$point->{'hae'}||$point->{'elev'}||0;
Condition0%0/14
$point->{'alt'} || $point->{'altitude'} || $point->{'elevation'} || $point->{'hae'} || $point->{'elev'} || 0
l!l
00
$point->{"alt"} or $point->{"altitude"} or $point->{"elevation"} or $point->{"hae"} or $point->{"elev"}
l!l&&r!l&&!r
000
$point->{"alt"} or $point->{"altitude"} or $point->{"elevation"} or $point->{"hae"}
l!l&&r!l&&!r
000
$point->{"alt"} or $point->{"altitude"} or $point->{"elevation"}
l!l&&r!l&&!r
000
$point->{"alt"} or $point->{"altitude"}
l!l&&r!l&&!r
000
MC/DC0%0/5
$point->{'alt'} || $point->{'altitude'} || $point->{'elevation'} || $point->{'hae'} || $point->{'elev'} || 0
$point->{"alt"} $point->{"altitude"} $point->{"elevation"} $point->{"hae"} $point->{"elev"}
Truth table0%0/6
A or B or C or D or E
A= $point->{"alt"}B= $point->{"altitude"}C= $point->{"elevation"}D= $point->{"hae"}E= $point->{"elev"}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
195 } elsif (reftype($point) eq "ARRAY") {
196 #[$lon, $lat, $alt]
197 0 $data->{'lon'}=$point->[0];
198 0 $data->{'lat'}=$point->[1];
199 0 ▶ $data->{'alt'}=$point->[2]||0;
Condition0%0/2
$point->[2] || 0
l!l
00
MC/DC0%0/1
$point->[2] || 0
$point->[2]
Truth table0%0/2
A
A= $point->[2]
Aresult
11
00
200 }
201 0 $data->{$_}+=0 foreach qw{lat lon alt}; #convert to number to "trim" strings that look like numbers.
202 0 ▶ return wantarray ? %$data : $data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
203 }
204  
205 =head1 BUGS
206  
207 Please log on RT and send to the geo-perl email list.
208  
209 =head1 SUPPORT
210  
211 DavisNetworks.com supports all Perl applications including this package.
212  
213 =head1 AUTHOR
214  
215 Michael R. Davis (mrdvt92)
216 CPAN ID: MRDVT
217  
218 =head1 COPYRIGHT
219  
220 This program is free software licensed under the...
221  
222 The BSD License
223  
224 The full text of the license can be found in the LICENSE file included with this module.
225  
226 =head1 SEE ALSO
227  
228 L<Geo::GoogleEarth::Pluggable>, L<Scalar::Util>, L<XML::LibXML::LazyBuilder>
229  
230 =cut
231  
232 3 1;
« Pluggable/Style.pm ↑ Summary Pluggable/StyleMap.pm »