Leaflet/Icon.pm

filter: Statementstmt 51.5% 17 / 33 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 44.4% 4 / 9 Podpod 100% 4 / 4 totaltotal 40.9% 25 / 61 CC 7 SCAR 24.3
CC
7
Cov
37%
name
20.0
options
20.0
_method_name
2.0
CRAP 11.3
« Leaflet/DivIcon.pm ↑ Summary Leaflet/Rectangle.pm »
1 package Geo::Leaflet::Icon;
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{Package::New};
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = '0.04';
8 2 our $PACKAGE = __PACKAGE__;
9  
10 =head1 NAME
11  
12 Geo::Leaflet::Icon - Leaflet icon object
13  
14 =head1 SYNOPSIS
15  
16 use Geo::Leaflet;
17 my $map = Geo::Leaflet->new;
18  
19 =head1 DESCRIPTION
20  
21 This package constructs a Leaflet icon object for use in a L<Geo::Leaflet::Marker> object.
22  
23 =head1 CONSTRUCTORS
24  
25 =head2 new
26  
27 =head1 PROPERTIES
28  
29 =head2 name
30  
31 The JavaScript name for the icon object.
32  
33 Default: iconNNN
34  
35 =cut
36  
37 2 our $NAME_PREFIX = 'icon';
38 2 our $NAME_INDEX = 1;
39  
40 0 ▶sub name {
Subroutine name: not called CC=4 SCAR=30.0
Pod documented
41 0 my $self = shift;
42 0 ▶ $self->{'name'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
43 0 ▶ $self->{'name'} ||= sprintf(sprintf('%s%d', $NAME_PREFIX, $NAME_INDEX++));
Condition0%0/3
$self->{"name"} ||= sprintf(sprintf("%s%d", $Geo::Leaflet::Icon::NAME_PREFIX, $Geo::Leaflet::Icon::NAME_INDEX++))
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"name"} ||= sprintf(sprintf("%s%d", $Geo::Leaflet::Icon::NAME_PREFIX, $Geo::Leaflet::Icon::NAME_INDEX++))
$self->{"name"} sprintf(sprintf("%s%d", $Geo::Leaflet::Icon::NAME_PREFIX, $Geo::Leaflet::Icon::NAME_INDEX++))
Truth table0%0/3
A ||= B
A= $self->{"name"}B= sprintf(sprintf("%s%d", $Geo::Leaflet::Icon::NAME_PREFIX, $Geo::Leaflet::Icon::NAME_INDEX++))
ABresult
1X1
011
000
44 0 ▶ die("Error: $PACKAGE name invaild variable name") unless $self->{'name'} =~ m/\A[a-z_][a-z0-9_]*\Z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"name"} =~ /\A[a-z_][a-z0-9_]*\Z/i 0 0 0
45 0 return $self->{'name'};
46 }
47  
48 =head2 options
49  
50 =cut
51  
52 0 ▶sub options {
Subroutine options: not called CC=4 SCAR=30.0
Pod documented
53 0 my $self = shift;
54 0 ▶ $self->{'options'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
55 0 ▶ $self->{'options'} = {} unless $self->{'options'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"options"} 0 0 0
56 0 ▶ die("Error: $PACKAGE options must be a hash") unless ref($self->{'options'}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"options"} eq "HASH" 0 0 0
57 0 return $self->{'options'};
58 }
59  
60 =head1 METHODS
61  
62 =head2 stringify
63  
64 =cut
65  
66 0 ▶sub _method_name {'icon'};
Subroutine _method_name: not called CC=1 SCAR=6.9
67  
68 0 ▶sub stringify {
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
69 0 my $self = shift;
70 # var icon_name = L.icon({
71 # iconUrl: 'my-icon.png',
72 # iconSize: [38, 95],
73 # iconAnchor: [22, 94],
74 # popupAnchor: [-3, -76],
75 # shadowUrl: 'my-icon-shadow.png',
76 # shadowSize: [68, 95],
77 # shadowAnchor: [22, 94]
78 # });
79 0 return sprintf(q{L.%s(%s);}, $self->_method_name, $self->JSON->encode($self->options));
80 }
81  
82 =head2 JSON
83  
84 =cut
85  
86 0 ▶sub JSON {
Subroutine JSON: not called CC=1 SCAR=6.9
Pod documented
87 0 my $self = shift;
88 0 $self->{'JSON'} = JSON::XS->new->allow_nonref;
89 0 return $self->{'JSON'};
90 }
91  
92 =head1 SEE ALSO
93  
94 =head1 AUTHOR
95  
96 Michael R. Davis
97  
98 =head1 COPYRIGHT AND LICENSE
99  
100 Copyright (C) 2024 by Michael R. Davis
101  
102 MIT LICENSE
103  
104 =cut
105  
106 2 1;
« Leaflet/DivIcon.pm ↑ Summary Leaflet/Rectangle.pm »