| 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.06 | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||||||||||||||||
| 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 | 16 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
onload_render: called CC=42 SCAR=40.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 16 | ▶ | my $class = ref($_[0]) ? __PACKAGE__ : shift; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | # Configuration | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 16 | 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 | 13 | $params = Object::Configure::configure($class, $params); | |||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 13 | my $ged = $params->{'gedcom'}; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 13 | my $debug = $params->{'debug'}; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 13 | my $google_key = $params->{'google_key'}; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 13 | my $geocoder = $params->{'geocoder'}; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 13 | ▶ | my $height = $params->{'height'} || '400px'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$params->{'height'} || '400px'
MC/DC100%1/1
$params->{'height'} || '400px'
$params->{'height'}
Truth table100%2/2
A
A= $params->{'height'}
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 13 | ▶ | my $width = $params->{'width'} || '600px'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$params->{'width'} || '600px'
MC/DC100%1/1
$params->{'width'} || '600px'
$params->{'width'}
Truth table100%2/2
A
A= $params->{'width'}
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | # Storage for events | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 13 | my @events; | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 13 | ▶ | print "Parsing GEDCOM file...\n" if($debug); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | # Process all individuals | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 13 | foreach my $indi ($ged->individuals) { | |||||||||||||||||||||||||||||||||||||||||
| 159 | 12 | ▶ | next unless(ref($indi)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 12 | ▶ | my $name = $indi->name || 'Unknown'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$indi->name || 'Unknown'
MC/DC0%0/1
$indi->name || 'Unknown'
$indi->name
Truth table50%1/2
A
A= $indi->name
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 12 | $name =~ s/\///g; # Remove GEDCOM name delimiters | |||||||||||||||||||||||||||||||||||||||||
| 162 | 12 | $name =~ s/'/'/g; # Probably this is enough HTML::Entities | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | # Birth events | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 12 | ▶ | if (my $birth = $indi->birth) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 11 | ▶ | if (ref($birth) && (my $place = $birth->place)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $birth and my $place = $birth->place
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
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 10 | ▶ | push @events, { | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$birth->date || 'Unknown date'
MC/DC0%0/1
$birth->date || 'Unknown date'
$birth->date
Truth table50%1/2
A
A= $birth->date
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | type => 'birth', | ||||||||||||||||||||||||||||||||||||||||||
| 169 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 170 | place => $place, | ||||||||||||||||||||||||||||||||||||||||||
| 171 | date => $birth->date || 'Unknown date', | ||||||||||||||||||||||||||||||||||||||||||
| 172 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | # Death events | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 12 | ▶ | if (my $death = $indi->death) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | ▶ | if (ref($death) && (my $place = $death->place)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $death and my $place = $death->place
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
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | ▶ | push @events, { | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$death->date || 'Unknown date'
MC/DC0%0/1
$death->date || 'Unknown date'
$death->date
Truth table50%1/2
A
A= $death->date
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 13 | foreach my $fam ($ged->families) { | |||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | ▶ | next unless defined($fam) && ref($fam); # Yes, really | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $fam and ref $fam
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
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | ▶ | my $husband = (ref($fam->husband) && $fam->husband->name) ? $fam->husband->name : 'Unknown'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $fam->husband and $fam->husband->name
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
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 1 | ▶ | my $wife = (ref($fam->wife) && $fam->wife->name) ? $fam->wife->name : 'Unknown'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $fam->wife and $fam->wife->name
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
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | $husband =~ s/\///g; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | $wife =~ s/\///g; | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | ▶ | if (my $marriage = $fam->marriage) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | ▶ | if (ref($marriage) && (my $place = $marriage->place)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $marriage and my $place = $marriage->place
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
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | $husband =~ s/'/'/; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | $wife =~ s/'/'/; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | ▶ | push @events, { | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$marriage->date || 'Unknown date'
MC/DC0%0/1
$marriage->date || 'Unknown date'
$marriage->date
Truth table50%1/2
A
A= $marriage->date
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | type => 'marriage', | ||||||||||||||||||||||||||||||||||||||||||
| 205 | name => "$husband & $wife", | ||||||||||||||||||||||||||||||||||||||||||
| 206 | place => $place, | ||||||||||||||||||||||||||||||||||||||||||
| 207 | date => $marriage->date || 'Unknown date', | ||||||||||||||||||||||||||||||||||||||||||
| 208 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 13 | ▶ | print 'Found ', scalar(@events), " events with location data.\n" if($debug); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 13 | ▶ | print "Geocoding locations...\n" if($debug); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | # Geocode all events | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 13 | my @geocoded_events; | |||||||||||||||||||||||||||||||||||||||||
| 218 | my %cache; # TODO allow use of params->{cache} if given | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 13 | foreach my $event (@events) { | |||||||||||||||||||||||||||||||||||||||||
| 221 | 12 | my $place = $event->{place}; | |||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | # Check cache | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 12 | ▶ | unless (exists $cache{$place}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 11 | my $location = $geocoder->geocode(location => $place); | |||||||||||||||||||||||||||||||||||||||||
| 226 | 11 | my ($lat, $long) = _coordinates($location); | |||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 11 | ▶ | if (defined($lat) && defined($long)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $lat and defined $long
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
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 10 | $cache{$place} = { | |||||||||||||||||||||||||||||||||||||||||
| 230 | lat => $lat, | ||||||||||||||||||||||||||||||||||||||||||
| 231 | lon => $long, # The cache's own key, not a key of the result | ||||||||||||||||||||||||||||||||||||||||||
| 232 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 10 | ▶ | print "\tGeocoded: $place\n" if($debug); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 10 | ▶ | sleep 1 unless _is_local($location); # Be nice to geocoding service | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 1 | ▶ | print "\tFailed to geocode: $place\n" if($debug); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 1 | $cache{$place} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 1 | sleep 1; # Be nice to geocoding service | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 12 | ▶ | if ($cache{$place}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | push @geocoded_events, { | ||||||||||||||||||||||||||||||||||||||||||
| 245 | %$event, | ||||||||||||||||||||||||||||||||||||||||||
| 246 | lat => $cache{$place}{lat}, | ||||||||||||||||||||||||||||||||||||||||||
| 247 | lon => $cache{$place}{lon}, | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 11 | }; | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 13 | ▶ | print 'Successfully geocoded ', scalar(@geocoded_events), " events.\n" if($debug); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 13 | ▶ | return('', '') if(scalar(@geocoded_events) == 0); # Empty | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 8 | ▶ | print "Generating map...\n" if($debug); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | # Group events by location | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 8 | my %location_groups; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 8 | foreach my $event (@geocoded_events) { | |||||||||||||||||||||||||||||||||||||||||
| 261 | 11 | my $key = sprintf('%.6f,%.6f', $event->{lat}, $event->{lon}); | |||||||||||||||||||||||||||||||||||||||||
| 262 | 11 | push @{$location_groups{$key}}, $event; | |||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | # Generate map based on available API key | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 8 | my $map; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 8 | ▶ | if ($google_key) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | $map = _generate_google_map(\%location_groups, $height, $width, $google_key); | |||||||||||||||||||||||||||||||||||||||||
| 269 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 8 | $map = _generate_osm_map(\%location_groups, $height, $width); | |||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 8 | 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 | 11 | ▶ | sub _coordinates { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_coordinates: called CC=8 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 11 | my $location = shift; | |||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 11 | ▶ | return unless defined($location); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 10 | ▶ | if(blessed($location) && $location->can('latitude') && $location->can('longitude')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
builtin::blessed($location) and $location->can("latitude") and $location->can("longitude")
builtin::blessed($location) and $location->can("latitude")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 6 | return ($location->latitude(), $location->longitude()); | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 4 | ▶ | if(ref($location) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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"}
$location->{"long"} // $location->{"lng"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 10 | ▶ | sub _is_local { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_local: called CC=7 SCAR=20.0
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 10 | my $location = shift; | |||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 10 | ▶ | return 0 unless ref($location); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 10 | ▶ | return 0 if(ref($location) eq 'ARRAY'); # A flat [lat, lon] says nothing about provenance | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | # 'database' is set by every Geo::Coder::Free backend and names the one that | ||||||||||||||||||||||||||||||||||||||||||
| 314 | # answered, in one of two vocabularies (%LOCAL_DATABASES holds both). | ||||||||||||||||||||||||||||||||||||||||||
| 315 | # 'geocoder' names the distribution instead: Geo::Coder::Free has set it since | ||||||||||||||||||||||||||||||||||||||||||
| 316 | # 0.45, and a wrapper such as Geo::Coder::List stamps it on its own results, | ||||||||||||||||||||||||||||||||||||||||||
| 317 | # so it is tested second - a result carrying neither key is not guessed to be | ||||||||||||||||||||||||||||||||||||||||||
| 318 | # local. | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 10 | ▶ | return 1 if(defined($location->{'database'}) && $LOCAL_DATABASES{$location->{'database'}}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $location->{"database"} and $LOCAL_DATABASES{$location->{"database"}}
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"}}
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 5 | ▶ | return 1 if(defined($location->{'geocoder'}) && $location->{'geocoder'} =~ /^Geo::Coder::Free/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $location->{"geocoder"} and $location->{"geocoder"} =~ /^Geo::Coder::Free/
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/
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | # Generate HTML for grouped events | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 10 | ▶ | sub _generate_popup_html { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_popup_html: called CC=9 SCAR=22.6
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 10 | my ($events) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 10 | my $place = $events->[0]{place}; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 10 | my $event_count = scalar(@$events); | |||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | # Add scrollable container if more than 5 events | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 10 | my $container_start = ''; | |||||||||||||||||||||||||||||||||||||||||
| 334 | 10 | my $container_end = ''; | |||||||||||||||||||||||||||||||||||||||||
| 335 | 10 | ▶ | if ($event_count > 5) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | $container_start = '<div style="max-height: 300px; overflow-y: auto;">'; | |||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | $container_end = '</div>'; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 10 | my $html = "<b>$place</b><br><br>$container_start"; | |||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | # Group by type | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 10 | my %by_type; | |||||||||||||||||||||||||||||||||||||||||
| 344 | 10 | foreach my $event (@$events) { | |||||||||||||||||||||||||||||||||||||||||
| 345 | 11 | push @{$by_type{$event->{type}}}, $event; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | # Sort function for dates | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 1 | ▶ | my $sort_by_date = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=23.8
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | 1 | my $date_a = $a->{'date'}; | |||||||||||||||||||||||||||||||||||||||||
| 351 | 1 | my $date_b = $b->{'date'}; | |||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | # Put unknown dates at the end | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 1 | ▶ | return 1 if $date_a =~ /^Unknown/i && $date_b !~ /^Unknown/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$date_a =~ /^Unknown/i and not $date_b =~ /^Unknown/i
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
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | ▶ | return -1 if $date_b =~ /^Unknown/i && $date_a !~ /^Unknown/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$date_b =~ /^Unknown/i and not $date_a =~ /^Unknown/i
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
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 1 | ▶ | return 0 if $date_a =~ /^Unknown/i && $date_b =~ /^Unknown/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$date_a =~ /^Unknown/i and $date_b =~ /^Unknown/i
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
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 1 | return Date::Cmp::datecmp($date_a, $date_b); | |||||||||||||||||||||||||||||||||||||||||
| 359 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | # Add births | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 10 | ▶ | if ($by_type{birth}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 8 | $html .= '<b>Births:</b><br>'; | |||||||||||||||||||||||||||||||||||||||||
| 364 | 8 | foreach my $event (sort $sort_by_date @{$by_type{birth}}) { | |||||||||||||||||||||||||||||||||||||||||
| 365 | $html .= sprintf( | ||||||||||||||||||||||||||||||||||||||||||
| 366 | '<span style="color: green; font-size: 20px;">●</span> %s (%s)<br>', | ||||||||||||||||||||||||||||||||||||||||||
| 367 | $event->{name}, | ||||||||||||||||||||||||||||||||||||||||||
| 368 | $event->{date} | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 9 | ); | |||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 8 | $html .= '<br>'; | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | # Add marriages | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 10 | ▶ | if ($by_type{marriage}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 1 | $html .= '<b>Marriages:</b><br>'; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 1 | foreach my $event (sort $sort_by_date @{$by_type{marriage}}) { | |||||||||||||||||||||||||||||||||||||||||
| 378 | $html .= sprintf( | ||||||||||||||||||||||||||||||||||||||||||
| 379 | '<span style="color: blue; font-size: 20px;">●</span> %s (%s)<br>', | ||||||||||||||||||||||||||||||||||||||||||
| 380 | $event->{name}, | ||||||||||||||||||||||||||||||||||||||||||
| 381 | $event->{date} | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 1 | $html .= '<br>'; | |||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | # Add deaths | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 10 | ▶ | if ($by_type{death}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | $html .= '<b>Deaths:</b><br>'; | |||||||||||||||||||||||||||||||||||||||||
| 390 | 1 | foreach my $event (sort $sort_by_date @{$by_type{death}}) { | |||||||||||||||||||||||||||||||||||||||||
| 391 | $html .= sprintf( | ||||||||||||||||||||||||||||||||||||||||||
| 392 | '<span style="color: red; font-size: 20px;">●</span> %s (%s)<br>', | ||||||||||||||||||||||||||||||||||||||||||
| 393 | $event->{name}, | ||||||||||||||||||||||||||||||||||||||||||
| 394 | $event->{date} | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 10 | $html .= $container_end; | |||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 10 | return $html; | |||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | # Generate Google Maps | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | sub _generate_google_map { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_google_map: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | my ($location_groups, $height, $width, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | my $map = HTML::GoogleMaps::V3->new( | |||||||||||||||||||||||||||||||||||||||||
| 409 | key => $key, | ||||||||||||||||||||||||||||||||||||||||||
| 410 | height => $height, | ||||||||||||||||||||||||||||||||||||||||||
| 411 | width => $width | ||||||||||||||||||||||||||||||||||||||||||
| 412 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | # Add markers for each location | ||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | my $first = 1; | |||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | foreach my $loc_key (keys %$location_groups) { | |||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | my $events = $location_groups->{$loc_key}; | |||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | my ($lat, $lon) = split /,/, $loc_key; | |||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | my $html = _generate_popup_html($events); | |||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | $map->add_marker( | |||||||||||||||||||||||||||||||||||||||||
| 423 | point => [$lat, $lon], | ||||||||||||||||||||||||||||||||||||||||||
| 424 | html => $html, | ||||||||||||||||||||||||||||||||||||||||||
| 425 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | # Center on first location | ||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | if ($first) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $map->center([$lat, $lon]); | |||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | $map->zoom(4); | |||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | $first = 0; | |||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | return $map; | |||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | # Generate OpenStreetMap using HTML::OSM | ||||||||||||||||||||||||||||||||||||||||||
| 439 | 8 | ▶ | sub _generate_osm_map { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_osm_map: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 8 | my ($location_groups, $height, $width) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | # Create HTML::OSM object | ||||||||||||||||||||||||||||||||||||||||||
| 443 | 8 | my $osm = HTML::OSM->new(zoom => 12, height => $height, width => $width); | |||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | # Add markers for each location | ||||||||||||||||||||||||||||||||||||||||||
| 446 | 8 | foreach my $loc_key (keys %$location_groups) { | |||||||||||||||||||||||||||||||||||||||||
| 447 | 10 | my $events = $location_groups->{$loc_key}; | |||||||||||||||||||||||||||||||||||||||||
| 448 | 10 | my ($lat, $lon) = split /,/, $loc_key; | |||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 10 | my $html = _generate_popup_html($events); | |||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 10 | $osm->add_marker( | |||||||||||||||||||||||||||||||||||||||||
| 453 | point => [$lat, $lon], | ||||||||||||||||||||||||||||||||||||||||||
| 454 | html => $html, | ||||||||||||||||||||||||||||||||||||||||||
| 455 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | # Find location with most events | ||||||||||||||||||||||||||||||||||||||||||
| 459 | 8 | my ($center_lat, $center_lon) = (0, 0); | |||||||||||||||||||||||||||||||||||||||||
| 460 | 8 | my $max_events = 0; | |||||||||||||||||||||||||||||||||||||||||
| 461 | 8 | foreach my $loc_key (keys %$location_groups) { | |||||||||||||||||||||||||||||||||||||||||
| 462 | 10 | my $event_count = scalar(@{$location_groups->{$loc_key}}); | |||||||||||||||||||||||||||||||||||||||||
| 463 | 10 | ▶ | if ($event_count > $max_events) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | 8 | $max_events = $event_count; | |||||||||||||||||||||||||||||||||||||||||
| 465 | 8 | ($center_lat, $center_lon) = split /,/, $loc_key; | |||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | 8 | $osm->center([$center_lat, $center_lon]); | |||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | 8 | return $osm; | |||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | =item * L<Test Dashboard|https://nigelhorne.github.io/HTML-Genealogy-Map/coverage/> | ||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | =item * L<Configure an Object at Runtime|Object::Configure> | ||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | =head1 REPOSITORY | ||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | L<https://github.com/nigelhorne/HTML-Genealogy-Map> | ||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | This module is provided as-is without any warranty. | ||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | Please report any bugs or feature requests to C<bug-html-genealogy-map at rt.cpan.org>, | ||||||||||||||||||||||||||||||||||||||||||
| 495 | or through the web interface at | ||||||||||||||||||||||||||||||||||||||||||
| 496 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-Genealogy-Map>. | ||||||||||||||||||||||||||||||||||||||||||
| 497 | I will be notified, and then you'll | ||||||||||||||||||||||||||||||||||||||||||
| 498 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | perldoc HTML::Genalogy::Map | ||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | You can also look for information at: | ||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | =item * MetaCPAN | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | L<https://metacpan.org/dist/HTML-Genealogy-Map> | ||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-Genealogy-Map> | ||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | =item * CPAN Testers' Matrix | ||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | L<http://matrix.cpantesters.org/?dist=HTML-Genealogy-Map> | ||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | =item * CPAN Testers Dependencies | ||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | L<http://deps.cpantesters.org/?module=HTML::Genalogy::Map> | ||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | Nigel Horne, C<< <njh at nigelhorne.com> >> | ||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | =head1 LICENCE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | Copyright 2025-2026 Nigel Horne. | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | Usage is subject to the GPL2 licence terms. | ||||||||||||||||||||||||||||||||||||||||||
| 535 | If you use it, | ||||||||||||||||||||||||||||||||||||||||||
| 536 | please let me know. | ||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||