Leaflet/Marker.pm

filter: Statementstmt 86.8% 33 / 38 Branchbran 42.8% 6 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 100% 3 / 3 totaltotal 77.7% 49 / 63 CC 9 SCAR 10.6
CC
9
Cov
75%
_hash_to_json
4.5
lat
3.1
lon
3.1
CRAP 2.9
« Leaflet.pm ↑ Summary Leaflet/Circle.pm »
1 package Geo::Leaflet::Marker;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use base qw{Geo::Leaflet::Objects};
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.04';
7 2 our $PACKAGE = __PACKAGE__;
8  
9 =head1 NAME
10  
11 Geo::Leaflet::Marker - Leaflet marker object
12  
13 =head1 SYNOPSIS
14  
15 use Geo::Leaflet;
16 my $map = Geo::Leaflet->new;
17 my $marker = $map->marker(
18 lat => $lat,
19 lon => $lon,
20 );
21  
22 =head1 DESCRIPTION
23  
24 This package constructs a Leaflet marker object for use on a L<Geo::Leaflet> map.
25  
26 =head1 PROPERTIES
27  
28 =head2 lat
29  
30 =cut
31  
32 1 ▶sub lat {
Subroutine lat: called CC=3 SCAR=11.4
Pod documented
33 1 my $self = shift;
34 1 ▶ $self->{'lat'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
35 1 ▶ die("Error: lat required") unless defined $self->{'lat'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"lat"} 0 1 1
36 1 return $self->{'lat'};
37 }
38  
39 =head2 lon
40  
41 =cut
42  
43 1 ▶sub lon {
Subroutine lon: called CC=3 SCAR=11.4
Pod documented
44 1 my $self = shift;
45 1 ▶ $self->{'lon'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
46 1 ▶ die("Error: lon required") unless defined $self->{'lon'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"lon"} 0 1 1
47 1 return $self->{'lon'};
48 }
49  
50 =head2 options
51  
52 =head2 popup
53  
54 =head1 METHODS
55  
56 =head2 stringify
57  
58 =cut
59  
60 0 ▶sub _method_name {'marker'};
Subroutine _method_name: not called CC=1 SCAR=6.9
61  
62 1 ▶sub stringify {
Subroutine stringify: called CC=3 SCAR=11.1
Pod documented
63 1 my $self = shift;
64 1 my $options = $self->options;
65 1 my $value = shift;
66 #const object6 = L.marker([51.498,-0.09],
67 # {"icon":paddle_1})
68 # .addTo(map).bindPopup("marker icon popup").bindTooltip("marker icon tooltip");
69 1 my $class = 'marker';
70 1 my $addmap = '.addTo(map)';
71 1 ▶ my $popup = $self->popup ? sprintf('.bindPopup(%s)', $self->JSON->encode($self->popup)) : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->popup ? : 1 0 1
72 1 ▶ my $tooltip = $self->tooltip ? sprintf('.bindTooltip(%s)', $self->JSON->encode($self->tooltip)) : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->tooltip ? : 0 1 1
73 1 return sprintf(q{L.%s(%s, %s)%s%s%s;},
74 $class,
75 $self->JSON->encode([$self->lat, $self->lon]),
76 $self->_hash_to_json($self->options),
77 $addmap,
78 $popup,
79 $tooltip,
80 );
81 }
82  
83 #head2 _hash_to_json
84 #
85 #Custom JSON encoder! Unfortunately, no Perl encoders support function name encoding as needed here for "icon" keys
86 #
87 #cut
88  
89 1 ▶sub _hash_to_json {
Subroutine _hash_to_json: called CC=3 SCAR=15.0
90 1 my $self = shift;
91 1 my $hash = shift;
92 1 my $string = '';
93 1 foreach my $key (keys %$hash) {
94 0 my $value = $hash->{$key};
95 0 ▶ if ($key eq "icon") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq 'icon') { } 0 0 0
96 0 $string = $string . join(':', $self->JSON->encode($key), $value); #function name encoding is not supported by any perl package!
97 } else {
98 0 $string = $string . join(':', $self->JSON->encode($key), $self->JSON->encode($value));
99 }
100 }
101 1 return "{$string}";
102 }
103  
104 =head1 SEE ALSO
105  
106 =head1 AUTHOR
107  
108 Michael R. Davis
109  
110 =head1 COPYRIGHT AND LICENSE
111  
112 Copyright (C) 2024 by Michael R. Davis
113  
114 MIT LICENSE
115  
116 =cut
117  
118 2 1;
« Leaflet.pm ↑ Summary Leaflet/Circle.pm »