File Coverage

blib/lib/Geo/Leaflet/icon.pm
Criterion Covered Total %
statement 12 27 44.4
branch 0 12 0.0
condition n/a
subroutine 4 8 50.0
pod 4 4 100.0
total 20 51 39.2


line stmt bran cond sub pod time code
1             package Geo::Leaflet::icon;
2 2     2   14 use strict;
  2         5  
  2         107  
3 2     2   12 use warnings;
  2         5  
  2         121  
4 2     2   30 use base qw{Package::New};
  2         4  
  2         220  
5 2     2   14 use JSON::XS;
  2         4  
  2         1132  
6              
7             our $VERSION = '0.03';
8             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 object.
22              
23             =head1 CONSTRUCTORS
24              
25             =head2 new
26              
27             =head1 PROPERTIES
28              
29             =head2 name
30              
31             =cut
32              
33             sub name {
34 0     0 1   my $self = shift;
35 0 0         $self->{'name'} = shift if @_;
36 0 0         die("Error: $PACKAGE name required") unless defined $self->{'name'};
37 0 0         die("Error: $PACKAGE name invaild variable name") unless $self->{'name'} =~ m/\A[a-z_][a-z0-9_]*\Z/i;
38 0           return $self->{'name'};
39             }
40              
41             =head2 options
42              
43             =cut
44              
45             sub options {
46 0     0 1   my $self = shift;
47 0 0         $self->{'options'} = shift if @_;
48 0 0         $self->{'options'} = {} unless $self->{'options'};
49 0 0         die("Error: $PACKAGE options must be a hash") unless ref($self->{'options'}) eq 'HASH';
50 0           return $self->{'options'};
51             }
52              
53             =head1 METHODS
54              
55             =head2 stringify
56              
57             =cut
58              
59             sub stringify {
60 0     0 1   my $self = shift;
61             # var icon_name = L.icon({
62             # iconUrl: 'my-icon.png',
63             # iconSize: [38, 95],
64             # iconAnchor: [22, 94],
65             # popupAnchor: [-3, -76],
66             # shadowUrl: 'my-icon-shadow.png',
67             # shadowSize: [68, 95],
68             # shadowAnchor: [22, 94]
69             # });
70 0           return sprintf(q{L.icon(%s);}, $self->JSON->encode($self->options));
71             }
72              
73             =head2 JSON
74              
75             =cut
76              
77             sub JSON {
78 0     0 1   my $self = shift;
79 0           $self->{'JSON'} = JSON::XS->new->allow_nonref;
80 0           return $self->{'JSON'};
81             }
82              
83             =head1 SEE ALSO
84              
85             =head1 AUTHOR
86              
87             Michael R. Davis
88              
89             =head1 COPYRIGHT AND LICENSE
90              
91             Copyright (C) 2024 by Michael R. Davis
92              
93             MIT LICENSE
94              
95             =cut
96              
97             1;