Pluggable/Style.pm

filter: Statementstmt 33.3% 18 / 54 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 34 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 62.5% 5 / 8 Podpod 100% 3 / 3 totaltotal 18.9% 26 / 137 CC 28 SCAR 53.8
CC
28
Cov
16%
color
342.0
node
132.0
type
2.0
CRAP 217.6
↑ Summary Pluggable/Placemark.pm »
1 package Geo::GoogleEarth::Pluggable::Style;
2 1 ▶use base qw{Geo::GoogleEarth::Pluggable::StyleBase};
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Scalar::Util qw{reftype};
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use XML::LibXML::LazyBuilder qw{E};
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION='0.17';
9 1 our $PACKAGE=__PACKAGE__;
10  
11 =head1 NAME
12  
13 Geo::GoogleEarth::Pluggable::Style - Geo::GoogleEarth::Pluggable Style Object
14  
15 =head1 SYNOPSIS
16  
17 use Geo::GoogleEarth::Pluggable;
18 my $document=Geo::GoogleEarth::Pluggable->new();
19 my $style=$document->Style();
20  
21 =head1 DESCRIPTION
22  
23 Geo::GoogleEarth::Pluggable::Style is a L<Geo::GoogleEarth::Pluggable::Base> with a few other methods.
24  
25 =head1 USAGE
26  
27 my $style=$document->Style(id=>"Style_Internal_HREF",
28 iconHref=>"http://.../path/image.png");
29  
30 =head1 CONSTRUCTOR
31  
32 =head2 new
33  
34 my $style=$document->Style(id=>"Style_Internal_HREF",
35 iconHref=>"http://.../path/image.png");
36  
37 =head1 METHODS
38  
39 =head2 type
40  
41 Returns the object type.
42  
43 my $type=$style->type;
44  
45 =cut
46  
47 0 ▶sub type {"Style"};
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
48  
49 =head2 node
50  
51 =cut
52  
53 0 ▶sub node {
Subroutine node: not called CC=11 SCAR=48.8
Pod documented
54 0 my $self=shift;
55 0 my @element=();
56 0 foreach my $style (keys %$self) {
57 0 ▶ next if $style eq "document";
Branch: 1 branch
BranchTrueFalseTotal
if $style eq "document" 0 0 0
58 0 ▶ next if $style eq "id";
Branch: 1 branch
BranchTrueFalseTotal
if $style eq "id" 0 0 0
59 0 my @subelement=();
60 0 ▶ if (reftype($self->{$style}) eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($self->{$style}) eq 'HASH') { } 0 0 0
61 0 foreach my $key (keys %{$self->{$style}}) {
62 0 my $value=$self->{$style}->{$key};
63 #printf "Style: %s, Key: %s, Value: %s\n", $style, $key, $value;
64 #push @subelement, E(key=>{}, $key);
65 0 ▶ if ($key eq "color") {
Branch: 4 branches
BranchTrueFalseTotal
if ($key eq 'color') { } 0 0 0
elsif ($key eq 'href') { } 0 0 0
elsif (ref $value eq 'HASH') { } 0 0 0
elsif (ref $value eq 'ARRAY') { } 0 0 0
66 0 push @subelement, E($key=>{}, $self->color($value));
67 } elsif ($key eq "href") {
68 0 ▶ if ($style eq "ListStyle") { #Google Earth Inconsistency!
Branch: 1 branch
BranchTrueFalseTotal
if ($style eq 'ListStyle') { } 0 0 0
69 0 push @subelement, E(ItemIcon=>{}, E($key=>{}, $value));
70 } else {
71 0 push @subelement, E(Icon=>{}, E($key=>{}, $value)); #which way to default
72 }
73 } elsif (ref($value) eq "HASH") { #e.g. hotSpot
74 0 push @subelement, E($key=>$value);
75 } elsif (ref($value) eq "ARRAY") {
76 0 push @subelement, E($key=>{}, join(",", @$value));
77 } else {
78 0 push @subelement, E($key=>{}, $value);
79 }
80 }
81 } else {
82 0 warn("Warning: Expecting $style to be a hash reference.");
83 }
84 0 push @element, E($style=>{}, @subelement);
85 }
86 0 return E(Style=>{id=>$self->id}, @element);
87 }
88  
89 =head2 color
90  
91 Returns a color code for use in the XML structure given many different inputs.
92  
93 my $color=$style->color("FFFFFFFF"); #AABBGGRR in hex
94 my $color=$style->color({color="FFFFFFFF"});
95 my $color=$style->color({red=>255, green=>255, blue=>255, alpha=>255});
96 my $color=$style->color({rgb=>[255,255,255], alpha=>255});
97 my $color=$style->color({abgr=>[255,255,255,255]});
98 #my $color=$style->color({name=>"blue", alpha=>255}); #TODO with ColorNames
99  
100 Note: alpha can be 0-255 or "0%"-"100%"
101  
102 =cut
103  
104 0 ▶sub color {
Subroutine color: not called CC=18 SCAR=58.3
Pod documented
105 0 my $self=shift;
106 0 my $color=shift;
107 0 ▶ if (ref($color) eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $color eq 'HASH') { } 0 0 0
108 0 ▶ if (defined($color->{"color"})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $color->{'color'}) { } 0 0 0
109 0 ▶ return $color->{"color"} || "FFFFFFFF";
Condition0%0/2
$color->{'color'} || 'FFFFFFFF'
l!l
00
MC/DC0%0/1
$color->{'color'} || 'FFFFFFFF'
$color->{'color'}
Truth table0%0/2
A
A= $color->{'color'}
Aresult
11
00
110 } else {
111 0 ▶ my $a=$color->{"a"} || $color->{"alpha"} || $color->{"abgr"}->[0];
Condition0%0/6
$color->{'a'} || $color->{'alpha'} || $color->{'abgr'}[0]
l!l&&r!l&&!r
000
$color->{"a"} or $color->{"alpha"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$color->{'a'} || $color->{'alpha'} || $color->{'abgr'}[0]
$color->{"a"} $color->{"alpha"} $color->{'abgr'}[0]
Truth table0%0/4
A or B || C
A= $color->{"a"}B= $color->{"alpha"}C= $color->{'abgr'}[0]
ABCresult
1XX1
01X1
0011
0000
112 0 ▶ my $b=$color->{"b"} || $color->{"blue"} || $color->{"abgr"}->[1] || 0;
Condition0%0/8
$color->{'b'} || $color->{'blue'} || $color->{'abgr'}[1] || 0
l!l
00
$color->{"b"} or $color->{"blue"} or $color->{"abgr"}[1]
l!l&&r!l&&!r
000
$color->{"b"} or $color->{"blue"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$color->{'b'} || $color->{'blue'} || $color->{'abgr'}[1] || 0
$color->{"b"} $color->{"blue"} $color->{"abgr"}[1]
Truth table0%0/4
A or B or C
A= $color->{"b"}B= $color->{"blue"}C= $color->{"abgr"}[1]
ABCresult
1XX1
01X1
0011
0000
113 0 ▶ my $g=$color->{"g"} || $color->{"green"} || $color->{"abgr"}->[2] || 0;
Condition0%0/8
$color->{'g'} || $color->{'green'} || $color->{'abgr'}[2] || 0
l!l
00
$color->{"g"} or $color->{"green"} or $color->{"abgr"}[2]
l!l&&r!l&&!r
000
$color->{"g"} or $color->{"green"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$color->{'g'} || $color->{'green'} || $color->{'abgr'}[2] || 0
$color->{"g"} $color->{"green"} $color->{"abgr"}[2]
Truth table0%0/4
A or B or C
A= $color->{"g"}B= $color->{"green"}C= $color->{"abgr"}[2]
ABCresult
1XX1
01X1
0011
0000
114 0 ▶ my $r=$color->{"r"} || $color->{"red"} || $color->{"abgr"}->[3] || 0;
Condition0%0/8
$color->{'r'} || $color->{'red'} || $color->{'abgr'}[3] || 0
l!l
00
$color->{"r"} or $color->{"red"} or $color->{"abgr"}[3]
l!l&&r!l&&!r
000
$color->{"r"} or $color->{"red"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$color->{'r'} || $color->{'red'} || $color->{'abgr'}[3] || 0
$color->{"r"} $color->{"red"} $color->{"abgr"}[3]
Truth table0%0/4
A or B or C
A= $color->{"r"}B= $color->{"red"}C= $color->{"abgr"}[3]
ABCresult
1XX1
01X1
0011
0000
115 0 ▶ $a=255 unless defined $a;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a 0 0 0
116 0 ▶ if ($a=~m/(\d+)%/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a =~ /(\d+)%/) 0 0 0
117 0 $a=$1/100*255;
118 }
119 0 return unpack("H8", pack("C4", $a,$b,$g,$r));
120 }
121 } else {
122 0 ▶ return $color || "FFFFFFFF";
Condition0%0/2
$color || 'FFFFFFFF'
l!l
00
MC/DC0%0/1
$color || 'FFFFFFFF'
$color
Truth table0%0/2
A
A= $color
Aresult
11
00
123 }
124 }
125  
126 =head1 BUGS
127  
128 Please log on RT and send to the geo-perl email list.
129  
130 =head1 SUPPORT
131  
132 Try geo-perl email list.
133  
134 =head1 AUTHOR
135  
136 Michael R. Davis (mrdvt92)
137 CPAN ID: MRDVT
138  
139 =head1 COPYRIGHT
140  
141 This program is free software licensed under the...
142  
143 The BSD License
144  
145 The full text of the license can be found in the
146 LICENSE file included with this module.
147  
148 =head1 SEE ALSO
149  
150 L<Geo::GoogleEarth::Pluggable> creates a GoogleEarth Document.
151  
152 =cut
153  
154 1 1;
↑ Summary Pluggable/Placemark.pm »