Leaflet/marker.pm

filter: Statementstmt 89.1% 33 / 37 Branchbran 42.8% 6 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 80.3% 49 / 61 CC 9 SCAR 10.8
CC
9
Cov
76%
_hash_to_json
4.5
lat
3.1
lon
3.1
CRAP 3.0
« Leaflet/Base.pm ↑ Summary Leaflet.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.03';
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 sub lat {
33 1 ▶ my $self = shift;
Subroutine lat: called CC=3 SCAR=11.4
Pod documented
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 sub lon {
44 1 ▶ my $self = shift;
Subroutine lon: called CC=3 SCAR=11.4
Pod documented
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 sub stringify {
61 1 ▶ my $self = shift;
Subroutine stringify: called CC=3 SCAR=11.1
Pod documented
62 1 my $options = $self->options;
63 1 my $value = shift;
64 #const object6 = L.marker([51.498,-0.09],
65 # {"icon":paddle_1})
66 # .addTo(map).bindPopup("marker icon popup").bindTooltip("marker icon tooltip");
67 1 my $class = 'marker';
68 1 my $addmap = '.addTo(map)';
69 1 ▶ my $popup = $self->popup ? sprintf('.bindPopup(%s)', $self->JSON->encode($self->popup)) : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->popup ? : 1 0 1
70 1 ▶ my $tooltip = $self->tooltip ? sprintf('.bindTooltip(%s)', $self->JSON->encode($self->tooltip)) : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->tooltip ? : 0 1 1
71 1 return sprintf(q{L.%s(%s, %s)%s%s%s;},
72 $class,
73 $self->JSON->encode([$self->lat, $self->lon]),
74 $self->_hash_to_json($self->options),
75 $addmap,
76 $popup,
77 $tooltip,
78 );
79 }
80  
81 #head2 _hash_to_json
82 #
83 #Custom JSON encoder! Unfortunately, no Perl encoders support function name encoding as needed here for "icon" keys
84 #
85 #cut
86  
87 sub _hash_to_json {
88 1 ▶ my $self = shift;
Subroutine _hash_to_json: called CC=3 SCAR=15.0
89 1 my $hash = shift;
90 1 my $string = '';
91 1 foreach my $key (keys %$hash) {
92 0 my $value = $hash->{$key};
93 0 ▶ if ($key eq "icon") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq 'icon') { } 0 0 0
94 0 $string = $string . join(':', $self->JSON->encode($key), $value); #function name encoding is not supported by any perl package!
95 } else {
96 0 $string = $string . join(':', $self->JSON->encode($key), $self->JSON->encode($value));
97 }
98 }
99 1 return "{$string}";
100 }
101  
102 =head1 SEE ALSO
103  
104 =head1 AUTHOR
105  
106 Michael R. Davis
107  
108 =head1 COPYRIGHT AND LICENSE
109  
110 Copyright (C) 2024 by Michael R. Davis
111  
112 MIT LICENSE
113  
114 =cut
115  
116 2 1;
« Leaflet/Base.pm ↑ Summary Leaflet.pm »