diff --git a/dynamic-site/lib/Ged2site/Utils.pm b/dynamic-site/lib/Ged2site/Utils.pm index f8713119..8fab259b 100644 --- a/dynamic-site/lib/Ged2site/Utils.pm +++ b/dynamic-site/lib/Ged2site/Utils.pm @@ -16,6 +16,15 @@ BEGIN { Log::Any::Adapter->set('Log4perl'); } +=head1 SUBROUTINES/METHODS + +=head2 create_disc_cache + +Initialise a disc-based cache using the CHI module. +Supports multiple cache drivers, including BerkeleyDB, DBI, and Redis. + +=cut + sub create_disc_cache { my %args = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_; @@ -94,6 +103,13 @@ sub create_disc_cache { return CHI->new(%chi_args); } +=head2 create_memory_cache + +Initialise a memory-based cache using the CHI module. +Supports multiple cache drivers, including SharedMem, Memory, and Redis. + +=cut + sub create_memory_cache { my %args = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_; @@ -167,8 +183,16 @@ sub create_memory_cache { return CHI->new(%chi_args); } -# From http://www.geodatasource.com/developers/perl -# FIXME: use Math::Trig +=head2 distance + +Calculate the distance between two geographical points using latitude and longitude. +Supports distance in kilometres (K), nautical miles (N), or miles. + +From L +FIXME: use Math::Trig + +=cut + sub distance { my ($lat1, $lon1, $lat2, $lon2, $unit) = @_; my $theta = $lon1 - $lon2; @@ -176,9 +200,9 @@ sub distance { $dist = _acos($dist); $dist = _rad2deg($dist); $dist = $dist * 60 * 1.1515; - if ($unit eq "K") { - $dist = $dist * 1.609344; - } elsif ($unit eq "N") { + if ($unit eq 'K') { + $dist = $dist * 1.609344; # number of kilometres in a mile + } elsif ($unit eq 'N') { $dist = $dist * 0.8684; } return ($dist); diff --git a/ged2site b/ged2site index 6b6e539d..47aebc14 100755 --- a/ged2site +++ b/ged2site @@ -14122,8 +14122,8 @@ sub HTML::GoogleMaps::V3::_text_to_point { # IE, already a long/lat pair return [ reverse @$point_text ] if ref( $point_text ) eq 'ARRAY'; - if ( my @loc = $self->{geocoder}->geocode( location => $point_text ) ) { - if ( my $location = $loc[0] ) { + if( my @loc = $self->{geocoder}->geocode( location => $point_text ) ) { + if( my $location = $loc[0] ) { ################################################## # ADDITION: if(ref($location) eq 'Geo::Location::Point') { @@ -14135,7 +14135,7 @@ sub HTML::GoogleMaps::V3::_text_to_point { # END OF ADDITION ################################################## - if ( ref( $location ) ne 'HASH' ) { + if( ref( $location ) ne 'HASH' ) { warn "$point_text didn't return a HASH ref as first element from ->geocode"; return 0; } @@ -14757,44 +14757,32 @@ sub get_year_from_date($) # https://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html sub get_language { + my %langs = ( + 'br' => 'Breton', + 'de' => 'German', + 'en' => 'English', + 'fr' => 'French', + 'fa' => 'Farsi', + 'la' => 'Latin', + ); + + # Check the LANGUAGE environment variable if($ENV{'LANGUAGE'}) { - my %langs = ( - 'br' => 'Breton', - 'de' => 'German', - 'en' => 'English', - 'fr' => 'French', - 'fa' => 'Farsi', - 'la' => 'Latin' - ); - foreach my $language(split/:/, $ENV{'LANGUAGE'}) { - if(my $rc = $langs{$language}) { - return $rc; - } + for my $language (split /:/, $ENV{'LANGUAGE'}) { + return $langs{$language} if exists $langs{$language}; } } - foreach my $variable('LC_ALL', 'LC_MESSAGES', 'LANG') { - my $val = $ENV{$variable}; - next unless(defined($val)); - if($val =~ /^en/) { - return 'English'; - } - if($val =~ /^fr/) { - return 'French'; - } - if($val =~ /^de/) { - return 'German'; - } - if($val =~ /^fa/) { - return 'Farsi'; - } - if($val =~ /^la/) { - return 'Latin'; - } - if($val =~ /^br/) { - return 'Breton'; + # Check other environment variables + for my $variable('LC_ALL', 'LC_MESSAGES', 'LANG') { + if(my $val = $ENV{$variable}) { + if(my ($prefix) = $val =~ /^(\w{2})/) { + return $langs{$prefix} if exists $langs{$prefix}; + } } } + + # Fallback complain("Can't determine the language, falling back to English"); return 'English'; } @@ -15100,7 +15088,7 @@ sub twins $d = $dfn->parse_datetime($d->{'canonical'}); # Check if the sibling is a twin - if ($d == $birth_dt || $d == ($birth_dt - $oneday) || $d == ($birth_dt + $oneday)) { + if($d == $birth_dt || $d == ($birth_dt - $oneday) || $d == ($birth_dt + $oneday)) { push @twins, { sibling => $sibling, dob => $d }; } }