Skip to content

Commit

Permalink
Remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Oct 16, 2020
1 parent ab6bf63 commit 6f01c2b
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions ged2site
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ use Class::Simple::Cached 0.03;
use Class::Simple::Readonly::Cached 0.02;
use POSIX;

sub get_location($);

my %opts;
getopts('cdfFG:g:h:J:lL:mwWvx:', \%opts);

Expand Down Expand Up @@ -808,23 +810,8 @@ foreach my $person(@everyone) {
print_person({ person => $person });
print $xml "\n\t</person>";
print $csv "\n";
if($opts{'v'}) {
my $log = $geocoder->log();
$geocoder->flush();
foreach my $l(@{$log}) {
print $l->{location}, ': ' if($l->{'location'});
if($l->{geocoder}) {
if($l->{error}) {
print $l->{timetaken}, 's with ', $l->{geocoder}, '(', $l->{error}, ')';
} else {
print $l->{timetaken}, 's with ', $l->{geocoder};
}
} else {
print 'cached';
}
print ', wantarray ', $l->{wantarray}, "\n";
}
}

dump_geocoder_log();
}
last if($opts{'L'} && ($index == $opts{'L'}));
last if(MAX_INDEX && ($index >= MAX_INDEX));
Expand Down Expand Up @@ -9257,7 +9244,8 @@ sub dateofdeath {
}

# Given a place return its latitude and longitude
sub get_location {
sub get_location($)
{
my $place = shift;

return unless(defined($geocoder));
Expand All @@ -9274,27 +9262,41 @@ sub get_location {
$rc->lat($location->{geometry}{location}{lat});
return $rc;
}
my $log = $geocoder->log();
$geocoder->flush();
foreach my $l(@{$log}) {
print $l->{location}, ': ' if($l->{'location'});
if($l->{geocoder}) {
if($l->{error}) {
print $l->{timetaken}, 's with ', $l->{geocoder}, '(', $l->{error}, ')';
} else {
print $l->{timetaken}, 's with ', $l->{geocoder};
}
} else {
print 'cached';
}
print ', wantarray ', $l->{wantarray}, "\n";
}
dump_geocoder_log();

print Data::Dumper->new([\$location])->Dump();
print Data::Dumper->new([\@locations])->Dump();
complain({ warning => "Probable bug in Geo::Coder::List with '$place'" });
}
}

sub dump_geocoder_log
{
return unless($opts{'v'});
return unless(defined($geocoder));

my $log = $geocoder->log();
$geocoder->flush();
print Data::Dumper->new([$log])->Dump() if($log);
foreach my $l(@{$log}) {
if($l->{'line'}) {
print 'Line ', $l->{'line'}, ': ';
}
if($l->{'error'}) {
print $l->{'error'}, ', ';
}
if($l->{geocoder}) {
if($l->{error}) {
print $l->{location}, ': ', $l->{timetaken}, 's with ', $l->{geocoder}, '(', $l->{error}, ")\n";
} else {
print $l->{location}, ': ', $l->{timetaken}, 's with ', $l->{geocoder}, "\n";
}
} else {
print $l->{location}, ": cached\n";
}
}
}

# Capitalise the first character
sub sortoutcase {
my $field = lc(shift);
Expand Down

0 comments on commit 6f01c2b

Please sign in to comment.