1.02KiB; Perl | 2018-11-27 17:29:09+01 | Statements 34 | SLOC 36
1
package Ged2site::Display::facts;
2
3
# Display the facts page
4
5
use Ged2site::Display;
6
use File::Spec;
7
use JSON;
8
9 2
our @ISA = ('Ged2site::Display');
10
11
sub html {
12
	my $self = shift;
13
	my %args = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_;
14
15
	my $info = $self->{_info};
16
	my $allowed = {
17
		'page' => 'facts',
18
		'lang' => qr/^[A-Z][A-Z]/i,
19
		'lint_content' => qr/^\d$/,
20
	};
21
	my %params = %{$info->params({ allow => $allowed })};
22
23
	my $json_file = File::Spec->catfile($args{'databasedir'}, 'facts.json');
24
25
	my $people = $args{'people'};
26
	my $p;
27
28
	if(open(my $json, '<', $json_file)) {
29
		my $facts = JSON->new()->utf8()->decode(<$json>);
30
		close($json);
31
		if(my $fb = $facts->{'first_birth'}) {
32
			$fb->{'person'} = $people->fetchrow_hashref(entry => delete $fb->{'xref'});
33
		}
34
		if(my $oa = $facts->{'oldest_age'}) {
35
			$oa->{'person'} = $people->fetchrow_hashref(entry => delete $oa->{'xref'});
36
		}
37
		$p->{'facts'} = $facts;
38
	} else {
39
		$p->{'error'} = "Can't open $json_file";
40
	}
41
	$p->{'updated'} = $people->updated();
42
	return $self->SUPER::html($p);
43
}
44
45
1;