File Coverage

blib/lib/Geo/Leaflet/Base.pm
Criterion Covered Total %
statement 26 27 96.3
branch 7 10 70.0
condition 4 6 66.6
subroutine 7 8 87.5
pod 3 3 100.0
total 47 54 87.0


line stmt bran cond sub pod time code
1             package Geo::Leaflet::Base;
2 2     2   17 use strict;
  2         3  
  2         81  
3 2     2   11 use warnings;
  2         3  
  2         88  
4 2     2   9 use base qw{Package::New};
  2         3  
  2         299  
5 2     2   1402 use JSON::XS;
  2         17864  
  2         553  
6              
7             our $VERSION = '0.04';
8             our $PACKAGE = __PACKAGE__;
9              
10             =head1 NAME
11              
12             Geo::Leaflet::Base - Leaflet base object
13              
14             =head1 SYNOPSIS
15              
16             use Geo::Leaflet;
17             my $map = Geo::Leaflet->new;
18              
19             =head1 DESCRIPTION
20              
21             This package provides a base package for L map objects.
22              
23             =head1 CONSTRUCTORS
24              
25             =head2 new
26            
27             =head1 PROPERTIES
28              
29             =head2 options
30              
31             =cut
32              
33             sub options {
34 6     6 1 5 my $self = shift;
35 6 50       9 $self->{'options'} = shift if @_;
36 6 100       9 $self->{'options'} = {} unless $self->{'options'};
37 6 50       9 die("Error: options must be a hash") unless ref($self->{'options'}) eq 'HASH';
38 6         37 return $self->{'options'};
39             }
40              
41             =head1 METHODS
42              
43             =head2 stringify_base
44              
45             =cut
46              
47 0     0   0 sub _method_name {die};
48              
49             sub stringify_base {
50 3     3 1 4 my $self = shift;
51 3         8 my $value = shift;
52             #const tiles = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
53             # maxZoom: 19,
54             # attribution: '© OpenStreetMap'
55             # }).addTo(map);
56             #
57             #const circle = L.circle([51.508, -0.11], {
58             # color: 'red',
59             # fillColor: '#f03',
60             # fillOpacity: 0.5,
61             # radius: 500
62             # }).addTo(map);
63 3         3 my $addmap = '.addTo(map)';
64 3 100 66     20 my $popup = $self->can('popup') && $self->popup ? sprintf('.bindPopup(%s)', $self->JSON->encode($self->popup)) : '';
65 3 50 66     11 my $tooltip = $self->can('tooltip') && $self->tooltip ? sprintf('.bindTooltip(%s)', $self->JSON->encode($self->tooltip)) : '';
66 3         7 return sprintf(q{L.%s(%s, %s)%s%s%s;},
67             $self->_method_name,
68             $self->JSON->encode($value),
69             $self->JSON->encode($self->options),
70             $addmap,
71             $popup,
72             $tooltip,
73             );
74             }
75              
76             =head2 JSON
77              
78             =cut
79              
80             sub JSON {
81 10     10 1 11 my $self = shift;
82 10         22 $self->{'JSON'} = JSON::XS->new->allow_nonref;
83 10         34 return $self->{'JSON'};
84             }
85              
86             =head1 SEE ALSO
87              
88             =head1 AUTHOR
89              
90             Michael R. Davis
91              
92             =head1 COPYRIGHT AND LICENSE
93              
94             Copyright (C) 2024 by Michael R. Davis
95              
96             MIT LICENSE
97              
98             =cut
99              
100             1;