Pluggable/Placemark.pm

filter: Statementstmt 75.3% 61 / 81 Branchbran 42.5% 17 / 40 Conditioncond 10.5% 4 / 38 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 86.6% 13 / 15 Podpod 100% 10 / 10 totaltotal 51.7% 105 / 203 CC 36 SCAR 43.7
CC
36
Cov
52%
point_normalize
191.4
node
8.1
styleUrl
6.3
CRAP 79.3
« Pluggable/Style.pm ↑ Summary Pluggable/StyleMap.pm »
1 package Geo::GoogleEarth::Pluggable::Placemark;
2 5 ▶use base qw{Geo::GoogleEarth::Pluggable::Base};
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Scalar::Util qw{reftype blessed};
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use XML::LibXML::LazyBuilder qw{E};
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 our $VERSION='0.17';
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 15 ▶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 5 ▶sub style {
Subroutine style: called CC=2 SCAR=7.1
Pod documented
41 5 my $self=shift;
42 5 ▶ $self->{"style"}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 5 5
43 5 return $self->{"style"};
44 }
45  
46 =head2 styleUrl
47  
48 This overrides style->url if defined.
49  
50 =cut
51  
52 5 ▶sub styleUrl {
Subroutine styleUrl: called CC=5 SCAR=18.4
Pod documented
53 5 my $self=shift;
54 5 my $url=undef;
55 5 ▶ $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 5 5
Condition33%1/3
builtin::blessed($self->style) and $self->style->can("url")
!ll&&!rl&&r
500
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 5 ▶ $self->{"styleUrl"}||=$url;
Condition33%1/3
$self->{"styleUrl"} ||= $url
l!l&&r!l&&!r
005
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 5 ▶ $self->{"styleUrl"}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 5 5
58 5 return $self->{"styleUrl"};
59 }
60  
61 =head2 LookAt
62  
63 Sets or returns the LookAt Object
64  
65 =cut
66  
67 0 ▶sub LookAt {
Subroutine LookAt: not called CC=2 SCAR=17.9
Pod documented
68 0 my $self=shift;
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 5 ▶sub visibility {
Subroutine visibility: called CC=2 SCAR=7.1
Pod documented
82 5 my $self=shift;
83 5 ▶ $self->{"visibility"}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 5 5
84 5 return $self->{"visibility"};
85 }
86  
87 =head2 node
88  
89 =cut
90  
91 5 ▶sub node {
Subroutine node: called CC=7 SCAR=20.9
Pod documented
92 5 my $self=shift;
93 5 my @element=();
94 5 ▶ push @element, $self->lookat->node
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->lookat and $self->lookat->can("node") 0 5 5
Condition33%1/3
ref $self->lookat and $self->lookat->can("node")
!ll&&!rl&&r
500
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 5 ▶ push @element, E(name=>{}, $self->name)
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->name 5 0 5
97 if defined $self->name;
98 5 push @element, E(Snippet=>{maxLines=>scalar(@{$self->Snippet})}, join("\n", @{$self->Snippet}));
99 5 ▶ push @element, E(description=>{}, $self->description)
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->description 0 5 5
100 if defined $self->description;
101 5 ▶ push @element, E(visibility=>{}, $self->visibility)
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->visibility 0 5 5
102 if defined $self->visibility;
103 5 ▶ push @element, E(styleUrl=>{}, $self->styleUrl)
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->styleUrl 0 5 5
104 if defined $self->styleUrl;
105 5 push @element, $self->subnode;
106 5 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 0 ▶sub coordinates {
Subroutine coordinates: not called CC=2 SCAR=17.9
Pod documented
131 0 my $self=shift;
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 4 ▶sub coordinates_stringify {
Subroutine coordinates_stringify: called CC=3 SCAR=11.4
Pod documented
141 4 my $self=shift;
142 4 ▶ my $data=@_ ? shift : $self->coordinates;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 4 0 4
143 4 my $string="";
144 4 ▶ if (ref($data) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data eq 'ARRAY') { } 4 0 4
145 4 $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 4 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 24 ▶sub point_stringify {
Subroutine point_stringify: called CC=1 SCAR=0.0
Pod documented
159 24 my $self=shift;
160 24 my %data=$self->point_normalize(@_);
161 24 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 24 ▶sub point_normalize {
Subroutine point_normalize: called CC=20 SCAR=52.5
Pod documented
173 24 my $self=shift;
174 24 my $point=shift;
175 24 my $data={};
176 24 ▶ if (ref($point) eq "Geo::Point") {
Branch: 5 branches
BranchTrueFalseTotal
if (ref $point eq 'Geo::Point') { } 0 24 24
elsif (ref $point eq 'GPS::Point') { } 0 24 24
elsif (ref $point eq 'Net::GPSD::Point') { } 0 24 24
elsif (builtin::reftype($point) eq 'HASH') { } 0 24 24
elsif (builtin::reftype($point) eq 'ARRAY') { } 24 0 24
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 24 $data->{'lon'}=$point->[0];
198 24 $data->{'lat'}=$point->[1];
199 24 ▶ $data->{'alt'}=$point->[2]||0;
Condition50%1/2
$point->[2] || 0
l!l
024
MC/DC0%0/1
$point->[2] || 0
$point->[2]
Truth table50%1/2
A
A= $point->[2]
Aresult
11
00
200 }
201 24 $data->{$_}+=0 foreach qw{lat lon alt}; #convert to number to "trim" strings that look like numbers.
202 24 ▶ return wantarray ? %$data : $data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 24 0 24
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 5 1;
« Pluggable/Style.pm ↑ Summary Pluggable/StyleMap.pm »