blib/lib/HTML/Genealogy/Map.pm

filter: Statementstmt 90.8% 168 / 185 Branchbran 75.0% 60 / 80 Conditioncond 50.0% 30 / 60 MC/DCmcdc 19.4% 7 / 36 Subroutinesub 94.7% 18 / 19 Podpod 100% 1 / 1 totaltotal 74.5% 284 / 381 CC 74 SCAR 33.7
CC
74
Cov
79%
onload_render
55.0
_generate_google_map
12.0
__ANON__
10.9
CRAP 29.0
↑ Summary
1 package HTML::Genealogy::Map;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use open qw(:std :encoding(UTF-8));
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Date::Cmp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use HTML::GoogleMaps::V3;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use HTML::OSM;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Object::Configure 0.15;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use Params::Get 0.13;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use Params::Validate::Strict 0.16;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 =head1 NAME
20  
21 HTML::Genealogy::Map - Extract and map genealogical events from a GEDCOM file
22  
23 =head1 VERSION
24  
25 Version 0.05
26  
27 =cut
28  
29 3 our $VERSION = '0.05';
30  
31 # The backends of Geo::Coder::Free that answer from a local database, named as
32 # they put themselves in a result's 'database' key.
33 3 my %LOCAL_DATABASES = map { $_ => 1 } qw(OpenAddresses MaxMind Local Geo::Coder::Free::Local);
34  
35 =head1 DESCRIPTION
36  
37 This module parses GEDCOM genealogy files and creates an interactive map showing
38 the locations of births, marriages, and deaths. Events at the same location are
39 grouped together in a single marker with a scrollable popup.
40  
41 =head1 SUBROUTINES/METHODS
42  
43 =head2 onload_render
44  
45 Render the map.
46 It takes two mandatory and one optional parameter.
47 It returns an array of two elements, the items for the C<head> and C<body>.
48  
49 =over 4
50  
51 =item B<gedcom>
52  
53 L<GEDCOM> object to process.
54  
55 =item B<geocoder>
56  
57 Geocoder to use.
58 Its results are read through the coordinates in C<lat> and C<long>/C<lng> -
59 through C<latitude()>/C<longitude()> when the geocoder returns an object -
60 so L<Geo::Location::Point> and anything else L<HTML::OSM> accepts will do.
61 A result's C<database> says which local dataset answered, and an
62 L<Geo::Coder::Free> result therefore does not attract the courtesy delay that
63 a remote service gets.
64  
65 =item B<google_key>
66  
67 Key to Google's map API.
68  
69 =item B<debug>
70  
71 Enable print statements of what's going on
72  
73 =back
74  
75 =head1 FEATURES
76  
77 =over 4
78  
79 =item * Extracts births, marriages, and deaths with location data
80  
81 =item * Geocodes locations using multiple fallback providers
82  
83 =item * Groups events at the same location (within ~0.1m precision)
84  
85 =item * Color-coded event indicators (green=birth, blue=marriage, red=death)
86  
87 =item * Sorts events chronologically within each category
88  
89 =item * Scrollable popups for locations with more than 5 events
90  
91 =item * Persistent caching of geocoding results
92  
93 =item * For OpenStreetMap: centers on location with most events
94  
95 =back
96  
97 =head3 API SPECIFICATION
98  
99 =head4 INPUT
100  
101 {
102 'gedcom' => { 'type' => 'object', 'can' => 'individuals' },
103 'geocoder' => { 'type' => 'object', 'can' => 'geocode' },
104 'debug' => { 'type' => 'boolean', optional => 1 },
105 'google_key' => { 'type' => 'string', optional => 1, min => 39, max => 39, matches => qr/^AIza[0-9A-Za-z_-]{35}$/ },
106 'height' => { optional => 1 },
107 'width' => { optional => 1 }
108 }
109  
110 =head4 OUTPUT
111  
112 Argument error: croak
113 No matches found: undef
114  
115 Returns an array of two strings:
116  
117 {
118 'type' => 'array',
119 'min' => 2,
120 'max' => 2,
121 'schema' => { 'type' => 'string', min => 10 },
122 }
123  
124 =cut
125  
126 sub onload_render
127 15 ▶{
Subroutine onload_render: called CC=42 SCAR=40.1
Pod documented
128 15 ▶ my $class = ref($_[0]) ? __PACKAGE__ : shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 1 14 15
129  
130 # Configuration
131 15 my $params = Params::Validate::Strict::validate_strict({
132 args => Params::Get::get_params('gedcom', @_),
133 schema => {
134 'gedcom' => { 'type' => 'object', 'can' => 'individuals' },
135 'geocoder' => { 'type' => 'object', 'can' => 'geocode' },
136 'debug' => { 'type' => 'boolean', optional => 1 },
137 'google_key' => { 'type' => 'string', optional => 1, min => 39, max => 39, matches => qr/^AIza[0-9A-Za-z_-]{35}$/ },
138 'height' => { optional => 1, type => 'string' },
139 'width' => { optional => 1, type => 'string' },
140 }
141 });
142  
143 12 $params = Object::Configure::configure($class, $params);
144  
145 12 my $ged = $params->{'gedcom'};
146 12 my $debug = $params->{'debug'};
147 12 my $google_key = $params->{'google_key'};
148 12 my $geocoder = $params->{'geocoder'};
149 12 ▶ my $height = $params->{'height'} || '400px';
Condition100%2/2
$params->{'height'} || '400px'
l!l
39
MC/DC100%1/1
$params->{'height'} || '400px'
$params->{'height'}
Truth table100%2/2
A
A= $params->{'height'}
Aresult
11
00
150 12 ▶ my $width = $params->{'width'} || '600px';
Condition100%2/2
$params->{'width'} || '600px'
l!l
39
MC/DC100%1/1
$params->{'width'} || '600px'
$params->{'width'}
Truth table100%2/2
A
A= $params->{'width'}
Aresult
11
00
151  
152 # Storage for events
153 12 my @events;
154  
155 12 ▶ print "Parsing GEDCOM file...\n" if($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 1 11 12
156  
157 # Process all individuals
158 12 foreach my $indi ($ged->individuals) {
159 11 ▶ next unless(ref($indi));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $indi 0 11 11
160 11 ▶ my $name = $indi->name || 'Unknown';
Condition50%1/2
$indi->name || 'Unknown'
l!l
110
MC/DC0%0/1
$indi->name || 'Unknown'
$indi->name
Truth table50%1/2
A
A= $indi->name
Aresult
11
00
161 11 $name =~ s/\///g; # Remove GEDCOM name delimiters
162 11 $name =~ s/'/&apos;/g; # Probably this is enough HTML::Entities
163  
164 # Birth events
165 11 ▶ if (my $birth = $indi->birth) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $birth = $indi->birth) 10 1 11
166 10 ▶ if (ref($birth) && (my $place = $birth->place)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $birth and my $place = $birth->place) 9 1 10
Condition66%2/3
ref $birth and my $place = $birth->place
!ll&&!rl&&r
019
MC/DC50%1/2
ref $birth and my $place = $birth->place
ref $birth my $place = $birth->place
Truth table66%2/3
A and B
A= ref $birthB= my $place = $birth->place
ABresult
0X0
100
111
167 9 ▶ push @events, {
Condition50%1/2
$birth->date || 'Unknown date'
l!l
90
MC/DC0%0/1
$birth->date || 'Unknown date'
$birth->date
Truth table50%1/2
A
A= $birth->date
Aresult
11
00
168 type => 'birth',
169 name => $name,
170 place => $place,
171 date => $birth->date || 'Unknown date',
172 };
173 }
174 }
175  
176 # Death events
177 11 ▶ if (my $death = $indi->death) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $death = $indi->death) 1 10 11
178 1 ▶ if (ref($death) && (my $place = $death->place)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $death and my $place = $death->place) 1 0 1
Condition33%1/3
ref $death and my $place = $death->place
!ll&&!rl&&r
001
MC/DC0%0/2
ref $death and my $place = $death->place
ref $death my $place = $death->place
Truth table33%1/3
A and B
A= ref $deathB= my $place = $death->place
ABresult
0X0
100
111
179 1 ▶ push @events, {
Condition50%1/2
$death->date || 'Unknown date'
l!l
10
MC/DC0%0/1
$death->date || 'Unknown date'
$death->date
Truth table50%1/2
A
A= $death->date
Aresult
11
00
180 type => 'death',
181 name => $name,
182 place => $place,
183 date => $death->date || 'Unknown date',
184 };
185 }
186 }
187 }
188  
189 # Process all families (marriages)
190 12 foreach my $fam ($ged->families) {
191 1 ▶ next unless defined($fam) && ref($fam); # Yes, really
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fam and ref $fam 0 1 1
Condition33%1/3
defined $fam and ref $fam
!ll&&!rl&&r
001
MC/DC0%0/2
defined $fam and ref $fam
defined $fam ref $fam
Truth table33%1/3
A and B
A= defined $famB= ref $fam
ABresult
0X0
100
111
192  
193 1 ▶ my $husband = (ref($fam->husband) && $fam->husband->name) ? $fam->husband->name : 'Unknown';
Branch: 1 branch
BranchTrueFalseTotal
ref $fam->husband && $fam->husband->name ? : 1 0 1
Condition33%1/3
ref $fam->husband and $fam->husband->name
!ll&&!rl&&r
001
MC/DC0%0/2
ref $fam->husband and $fam->husband->name
ref $fam->husband $fam->husband->name
Truth table33%1/3
A and B
A= ref $fam->husbandB= $fam->husband->name
ABresult
0X0
100
111
194 1 ▶ my $wife = (ref($fam->wife) && $fam->wife->name) ? $fam->wife->name : 'Unknown';
Branch: 1 branch
BranchTrueFalseTotal
ref $fam->wife && $fam->wife->name ? : 1 0 1
Condition33%1/3
ref $fam->wife and $fam->wife->name
!ll&&!rl&&r
001
MC/DC0%0/2
ref $fam->wife and $fam->wife->name
ref $fam->wife $fam->wife->name
Truth table33%1/3
A and B
A= ref $fam->wifeB= $fam->wife->name
ABresult
0X0
100
111
195  
196 1 $husband =~ s/\///g;
197 1 $wife =~ s/\///g;
198  
199 1 ▶ if (my $marriage = $fam->marriage) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $marriage = $fam->marriage) 1 0 1
200 1 ▶ if (ref($marriage) && (my $place = $marriage->place)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $marriage and my $place = $marriage->place) 1 0 1
Condition33%1/3
ref $marriage and my $place = $marriage->place
!ll&&!rl&&r
001
MC/DC0%0/2
ref $marriage and my $place = $marriage->place
ref $marriage my $place = $marriage->place
Truth table33%1/3
A and B
A= ref $marriageB= my $place = $marriage->place
ABresult
0X0
100
111
201 1 $husband =~ s/'/&apos;/;
202 1 $wife =~ s/'/&apos;/;
203 1 ▶ push @events, {
Condition50%1/2
$marriage->date || 'Unknown date'
l!l
10
MC/DC0%0/1
$marriage->date || 'Unknown date'
$marriage->date
Truth table50%1/2
A
A= $marriage->date
Aresult
11
00
204 type => 'marriage',
205 name => "$husband &amp; $wife",
206 place => $place,
207 date => $marriage->date || 'Unknown date',
208 };
209 }
210 }
211 }
212  
213 12 ▶ print 'Found ', scalar(@events), " events with location data.\n" if($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 1 11 12
214 12 ▶ print "Geocoding locations...\n" if($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 1 11 12
215  
216 # Geocode all events
217 12 my @geocoded_events;
218 my %cache; # TODO allow use of params->{cache} if given
219  
220 12 foreach my $event (@events) {
221 11 my $place = $event->{place};
222  
223 # Check cache
224 11 ▶ unless (exists $cache{$place}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $cache{$place}) 10 1 11
225 10 my $location = $geocoder->geocode(location => $place);
226 10 my ($lat, $long) = _coordinates($location);
227  
228 10 ▶ if (defined($lat) && defined($long)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lat and defined $long) { } 9 1 10
Condition66%2/3
defined $lat and defined $long
!ll&&!rl&&r
109
MC/DC50%1/2
defined $lat and defined $long
defined $lat defined $long
Truth table66%2/3
A and B
A= defined $latB= defined $long
ABresult
0X0
100
111
229 9 $cache{$place} = {
230 lat => $lat,
231 lon => $long, # The cache's own key, not a key of the result
232 };
233 9 ▶ print "\tGeocoded: $place\n" if($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 9 9
234 9 ▶ sleep 1 unless _is_local($location); # Be nice to geocoding service
Branch: 1 branch
BranchTrueFalseTotal
unless _is_local($location) 3 6 9
235  
236 } else {
237 1 ▶ print "\tFailed to geocode: $place\n" if($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1 1
238 1 $cache{$place} = undef;
239 1 sleep 1; # Be nice to geocoding service
240 }
241 }
242  
243 11 ▶ if ($cache{$place}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache{$place}) 10 1 11
244 push @geocoded_events, {
245 %$event,
246 lat => $cache{$place}{lat},
247 lon => $cache{$place}{lon},
248 10 };
249 }
250 }
251  
252 12 ▶ print 'Successfully geocoded ', scalar(@geocoded_events), " events.\n" if($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 1 11 12
253  
254 12 ▶ return('', '') if(scalar(@geocoded_events) == 0); # Empty
Branch: 1 branch
BranchTrueFalseTotal
if scalar @geocoded_events == 0 5 7 12
255  
256 7 ▶ print "Generating map...\n" if($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 7 7
257  
258 # Group events by location
259 7 my %location_groups;
260 7 foreach my $event (@geocoded_events) {
261 10 my $key = sprintf('%.6f,%.6f', $event->{lat}, $event->{lon});
262 10 push @{$location_groups{$key}}, $event;
263 }
264  
265 # Generate map based on available API key
266 7 my $map;
267 7 ▶ if ($google_key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($google_key) { } 0 7 7
268 0 $map = _generate_google_map(\%location_groups, $height, $width, $google_key);
269 } else {
270 7 $map = _generate_osm_map(\%location_groups, $height, $width);
271 }
272  
273 7 return $map->onload_render();
274 }
275  
276 # Purpose: Read the position out of a geocoder result.
277 # Entry: $location — a Geo::Location::Point (or anything else with
278 # latitude()/longitude(), which is what HTML::OSM accepts), or a
279 # plain hashref from another geocoder, or undef.
280 # Exit: ($lat, $lon) with either possibly undef; an empty list for a result
281 # that carries no position.
282 10 ▶sub _coordinates {
Subroutine _coordinates: called CC=8 SCAR=23.1
283 10 my $location = shift;
284  
285 10 ▶ return unless defined($location);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $location 1 9 10
286  
287 9 ▶ if(blessed($location) && $location->can('latitude') && $location->can('longitude')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($location) and $location->can("latitude") and $location->can("longitude")) 5 4 9
Condition66%4/6
builtin::blessed($location) and $location->can("latitude") and $location->can("longitude")
!ll&&!rl&&r
405
builtin::blessed($location) and $location->can("latitude")
!ll&&!rl&&r
405
MC/DC33%1/3
builtin::blessed($location) and $location->can("latitude") and $location->can("longitude")
builtin::blessed($location) $location->can("latitude") $location->can("longitude")
Truth table50%2/4
A and B and C
A= builtin::blessed($location)B= $location->can("latitude")C= $location->can("longitude")
ABCresult
0XX0
10X0
1100
1111
288 5 return ($location->latitude(), $location->longitude());
289 }
290  
291 4 ▶ if(ref($location) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $location eq "HASH") 4 0 4
292 # lat/long/lng are the keys Geo::Location::Point itself builds; 'lon' is
293 # only a third fallback, for geocoders that spell longitude that way. It
294 # is not part of the point interface: only one of Geo::Coder::Free's
295 # MaxMind shortcuts ever sets it.
296 return ($location->{'lat'},
297 4 ▶ $location->{'long'} // $location->{'lng'} // $location->{'lon'});
Condition33%2/6
($location->{"long"} // $location->{"lng"}) // $location->{"lon"}
l!l&&r!l&&!r
040
$location->{"long"} // $location->{"lng"}
l!l&&r!l&&!r
004
MC/DC0%0/3
($location->{"long"} // $location->{"lng"}) // $location->{"lon"}
$location->{"long"} $location->{"lng"} $location->{"lon"}
Truth table25%1/4
A // B // C
A= $location->{"long"}B= $location->{"lng"}C= $location->{"lon"}
ABCresult
1XX1
01X1
0011
0000
298 }
299  
300 0 return;
301 }
302  
303 # Purpose: Is this result from a local dataset, so that it needs no courtesy
304 # delay before the next lookup?
305 # Entry: $location — a geocoder result.
306 # Exit: 1 if it came from an offline database, 0 otherwise.
307 9 ▶sub _is_local {
Subroutine _is_local: called CC=7 SCAR=20.0
308 9 my $location = shift;
309  
310 9 ▶ return 0 unless ref($location);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $location 0 9 9
311 9 ▶ return 0 if(ref($location) eq 'ARRAY'); # A flat [lat, lon] says nothing about provenance
Branch: 1 branch
BranchTrueFalseTotal
if ref $location eq "ARRAY" 0 9 9
312  
313 # 'database' is set by every Geo::Coder::Free backend and names the one that
314 # answered. 'geocoder' is a secondary hint, stamped by wrappers such as
315 # Geo::Coder::List - Geo::Coder::Free itself never sets it, so it is tested
316 # second and is never the only evidence of a local lookup.
317 9 ▶ return 1 if(defined($location->{'database'}) && $LOCAL_DATABASES{$location->{'database'}});
Branch: 1 branch
BranchTrueFalseTotal
if defined $location->{"database"} and $LOCAL_DATABASES{$location->{"database"}} 5 4 9
Condition66%2/3
defined $location->{"database"} and $LOCAL_DATABASES{$location->{"database"}}
!ll&&!rl&&r
405
MC/DC50%1/2
defined $location->{"database"} and $LOCAL_DATABASES{$location->{"database"}}
defined $location->{"database"} $LOCAL_DATABASES{$location->{"database"}}
Truth table66%2/3
A and B
A= defined $location->{"database"}B= $LOCAL_DATABASES{$location->{"database"}}
ABresult
0X0
100
111
318 4 ▶ return 1 if(defined($location->{'geocoder'}) && $location->{'geocoder'} =~ /^Geo::Coder::Free/);
Branch: 1 branch
BranchTrueFalseTotal
if defined $location->{"geocoder"} and $location->{"geocoder"} =~ /^Geo::Coder::Free/ 1 3 4
Condition66%2/3
defined $location->{"geocoder"} and $location->{"geocoder"} =~ /^Geo::Coder::Free/
!ll&&!rl&&r
031
MC/DC50%1/2
defined $location->{"geocoder"} and $location->{"geocoder"} =~ /^Geo::Coder::Free/
defined $location->{"geocoder"} $location->{"geocoder"} =~ /^Geo::Coder::Free/
Truth table66%2/3
A and B
A= defined $location->{"geocoder"}B= $location->{"geocoder"} =~ /^Geo::Coder::Free/
ABresult
0X0
100
111
319  
320 3 return 0;
321 }
322  
323 # Generate HTML for grouped events
324 9 ▶sub _generate_popup_html {
Subroutine _generate_popup_html: called CC=9 SCAR=22.6
325 9 my ($events) = @_;
326  
327 9 my $place = $events->[0]{place};
328 9 my $event_count = scalar(@$events);
329  
330 # Add scrollable container if more than 5 events
331 9 my $container_start = '';
332 9 my $container_end = '';
333 9 ▶ if ($event_count > 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event_count > 5) 0 9 9
334 0 $container_start = '<div style="max-height: 300px; overflow-y: auto;">';
335 0 $container_end = '</div>';
336 }
337  
338 9 my $html = "<b>$place</b><br><br>$container_start";
339  
340 # Group by type
341 9 my %by_type;
342 9 foreach my $event (@$events) {
343 10 push @{$by_type{$event->{type}}}, $event;
344 }
345  
346 # Sort function for dates
347 1 ▶ my $sort_by_date = sub {
Subroutine __ANON__: called CC=7 SCAR=23.8
348 1 my $date_a = $a->{'date'};
349 1 my $date_b = $b->{'date'};
350  
351 # Put unknown dates at the end
352 1 ▶ return 1 if $date_a =~ /^Unknown/i && $date_b !~ /^Unknown/i;
Branch: 1 branch
BranchTrueFalseTotal
if $date_a =~ /^Unknown/i and not $date_b =~ /^Unknown/i 0 1 1
Condition33%1/3
$date_a =~ /^Unknown/i and not $date_b =~ /^Unknown/i
!ll&&!rl&&r
100
MC/DC0%0/2
$date_a =~ /^Unknown/i and not $date_b =~ /^Unknown/i
$date_a =~ /^Unknown/i not $date_b =~ /^Unknown/i
Truth table33%1/3
A and not(B)
A= $date_a =~ /^Unknown/iB= not $date_b =~ /^Unknown/i
ABresult
0X0
100
111
353 1 ▶ return -1 if $date_b =~ /^Unknown/i && $date_a !~ /^Unknown/i;
Branch: 1 branch
BranchTrueFalseTotal
if $date_b =~ /^Unknown/i and not $date_a =~ /^Unknown/i 0 1 1
Condition33%1/3
$date_b =~ /^Unknown/i and not $date_a =~ /^Unknown/i
!ll&&!rl&&r
100
MC/DC0%0/2
$date_b =~ /^Unknown/i and not $date_a =~ /^Unknown/i
$date_b =~ /^Unknown/i not $date_a =~ /^Unknown/i
Truth table33%1/3
A and not(B)
A= $date_b =~ /^Unknown/iB= not $date_a =~ /^Unknown/i
ABresult
0X0
100
111
354 1 ▶ return 0 if $date_a =~ /^Unknown/i && $date_b =~ /^Unknown/i;
Branch: 1 branch
BranchTrueFalseTotal
if $date_a =~ /^Unknown/i and $date_b =~ /^Unknown/i 0 1 1
Condition33%1/3
$date_a =~ /^Unknown/i and $date_b =~ /^Unknown/i
!ll&&!rl&&r
100
MC/DC0%0/2
$date_a =~ /^Unknown/i and $date_b =~ /^Unknown/i
$date_a =~ /^Unknown/i $date_b =~ /^Unknown/i
Truth table33%1/3
A and B
A= $date_a =~ /^Unknown/iB= $date_b =~ /^Unknown/i
ABresult
0X0
100
111
355  
356 1 return Date::Cmp::datecmp($date_a, $date_b);
357 9 };
358  
359 # Add births
360 9 ▶ if ($by_type{birth}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by_type{"birth"}) 7 2 9
361 7 $html .= '<b>Births:</b><br>';
362 7 foreach my $event (sort $sort_by_date @{$by_type{birth}}) {
363 $html .= sprintf(
364 '<span style="color: green; font-size: 20px;">&#x25CF;</span> %s (%s)<br>',
365 $event->{name},
366 $event->{date}
367 8 );
368 }
369 7 $html .= '<br>';
370 }
371  
372 # Add marriages
373 9 ▶ if ($by_type{marriage}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by_type{"marriage"}) 1 8 9
374 1 $html .= '<b>Marriages:</b><br>';
375 1 foreach my $event (sort $sort_by_date @{$by_type{marriage}}) {
376 $html .= sprintf(
377 '<span style="color: blue; font-size: 20px;">&#x25CF;</span> %s (%s)<br>',
378 $event->{name},
379 $event->{date}
380 1 );
381 }
382 1 $html .= '<br>';
383 }
384  
385 # Add deaths
386 9 ▶ if ($by_type{death}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by_type{"death"}) 1 8 9
387 1 $html .= '<b>Deaths:</b><br>';
388 1 foreach my $event (sort $sort_by_date @{$by_type{death}}) {
389 $html .= sprintf(
390 '<span style="color: red; font-size: 20px;">&#x25CF;</span> %s (%s)<br>',
391 $event->{name},
392 $event->{date}
393 1 );
394 }
395 }
396  
397 9 $html .= $container_end;
398  
399 9 return $html;
400 }
401  
402 # Generate Google Maps
403 0 ▶sub _generate_google_map {
Subroutine _generate_google_map: not called CC=3 SCAR=24.8
404 0 my ($location_groups, $height, $width, $key) = @_;
405  
406 0 my $map = HTML::GoogleMaps::V3->new(
407 key => $key,
408 height => $height,
409 width => $width
410 );
411  
412 # Add markers for each location
413 0 my $first = 1;
414 0 foreach my $loc_key (keys %$location_groups) {
415 0 my $events = $location_groups->{$loc_key};
416 0 my ($lat, $lon) = split /,/, $loc_key;
417  
418 0 my $html = _generate_popup_html($events);
419  
420 0 $map->add_marker(
421 point => [$lat, $lon],
422 html => $html,
423 );
424  
425 # Center on first location
426 0 ▶ if ($first) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first) 0 0 0
427 0 $map->center([$lat, $lon]);
428 0 $map->zoom(4);
429 0 $first = 0;
430 }
431 }
432  
433 0 return $map;
434 }
435  
436 # Generate OpenStreetMap using HTML::OSM
437 7 ▶sub _generate_osm_map {
Subroutine _generate_osm_map: called CC=4 SCAR=13.9
438 7 my ($location_groups, $height, $width) = @_;
439  
440 # Create HTML::OSM object
441 7 my $osm = HTML::OSM->new(zoom => 12, height => $height, width => $width);
442  
443 # Add markers for each location
444 7 foreach my $loc_key (keys %$location_groups) {
445 9 my $events = $location_groups->{$loc_key};
446 9 my ($lat, $lon) = split /,/, $loc_key;
447  
448 9 my $html = _generate_popup_html($events);
449  
450 9 $osm->add_marker(
451 point => [$lat, $lon],
452 html => $html,
453 );
454 }
455  
456 # Find location with most events
457 7 my ($center_lat, $center_lon) = (0, 0);
458 7 my $max_events = 0;
459 7 foreach my $loc_key (keys %$location_groups) {
460 9 my $event_count = scalar(@{$location_groups->{$loc_key}});
461 9 ▶ if ($event_count > $max_events) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event_count > $max_events) 7 2 9
462 7 $max_events = $event_count;
463 7 ($center_lat, $center_lon) = split /,/, $loc_key;
464 }
465 }
466  
467 7 $osm->center([$center_lat, $center_lon]);
468  
469 7 return $osm;
470 }
471  
472 =head1 BUGS
473  
474 =head1 SEE ALSO
475  
476 =over 4
477  
478 =item * L<Test Dashboard|https://nigelhorne.github.io/HTML-Genealogy-Map/coverage/>
479  
480 =item * L<Configure an Object at Runtime|Object::Configure>
481  
482 =back
483  
484 =head1 REPOSITORY
485  
486 L<https://github.com/nigelhorne/HTML-Genealogy-Map>
487  
488 =head1 SUPPORT
489  
490 This module is provided as-is without any warranty.
491  
492 Please report any bugs or feature requests to C<bug-html-genealogy-map at rt.cpan.org>,
493 or through the web interface at
494 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-Genealogy-Map>.
495 I will be notified, and then you'll
496 automatically be notified of progress on your bug as I make changes.
497  
498 You can find documentation for this module with the perldoc command.
499  
500 perldoc HTML::Genalogy::Map
501  
502 You can also look for information at:
503  
504 =over 4
505  
506 =item * MetaCPAN
507  
508 L<https://metacpan.org/dist/HTML-Genealogy-Map>
509  
510 =item * RT: CPAN's request tracker
511  
512 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-Genealogy-Map>
513  
514 =item * CPAN Testers' Matrix
515  
516 L<http://matrix.cpantesters.org/?dist=HTML-Genealogy-Map>
517  
518 =item * CPAN Testers Dependencies
519  
520 L<http://deps.cpantesters.org/?module=HTML::Genalogy::Map>
521  
522 =back
523  
524 =head1 AUTHOR
525  
526 Nigel Horne, C<< <njh at nigelhorne.com> >>
527  
528 =head1 LICENCE AND COPYRIGHT
529  
530 Copyright 2025-2026 Nigel Horne.
531  
532 Usage is subject to the GPL2 licence terms.
533 If you use it,
534 please let me know.
535  
536 =cut
537  
538 3 1;
↑ Summary