| 1 | =head1 NAME | ||||||||||||
| 2 | |||||||||||||
| 3 | SVG::Timeline::Genealogical::Person - a single person in a genealogical timeline | ||||||||||||
| 4 | |||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||
| 6 | |||||||||||||
| 7 | See L<SVG::Timeline::Genealogical>. | ||||||||||||
| 8 | |||||||||||||
| 9 | =cut | ||||||||||||
| 10 | |||||||||||||
| 11 | package SVG::Timeline::Genealogy::Person; | ||||||||||||
| 12 | |||||||||||||
| 13 | 2 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 2 | extends 'SVG::Timeline::Event'; | |||||||||||
| 15 | |||||||||||||
| 16 | 2 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | |||||||||||||
| 18 | 2 | ▶ | use Genealogy::Ahnentafel (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | |||||||||||||
| 20 | coerce __PACKAGE__, | ||||||||||||
| 21 | from 'HashRef', | ||||||||||||
| 22 | 1 | ▶ | via { __PACKAGE__->new($_) }; | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 23 | |||||||||||||
| 24 | 2 | has ahnen => ( | |||||||||||
| 25 | is => 'ro', | ||||||||||||
| 26 | isa => 'Int', | ||||||||||||
| 27 | ); | ||||||||||||
| 28 | |||||||||||||
| 29 | 2 | has +end => ( | |||||||||||
| 30 | is => 'ro', | ||||||||||||
| 31 | isa => 'Int', | ||||||||||||
| 32 | required => 0, | ||||||||||||
| 33 | ); | ||||||||||||
| 34 | |||||||||||||
| 35 | 2 | has generation => ( | |||||||||||
| 36 | is => 'ro', | ||||||||||||
| 37 | isa => 'Int', | ||||||||||||
| 38 | lazy_build => 1, | ||||||||||||
| 39 | ); | ||||||||||||
| 40 | |||||||||||||
| 41 | 1 | ▶ | sub _build_generation { | ||||||||||
|
Subroutine
_build_generation: called CC=1 SCAR=0.0
| |||||||||||||
| 42 | 1 | my $self = shift; | |||||||||||
| 43 | 1 | return Genealogy::Ahnentafel->new({ | |||||||||||
| 44 | ahnentafel => $self->ahnen, | ||||||||||||
| 45 | })->generation; | ||||||||||||
| 46 | } | ||||||||||||
| 47 | |||||||||||||
| 48 | # Array of colours - one for each generation. | ||||||||||||
| 49 | 2 | has colours => ( | |||||||||||
| 50 | is => 'ro', | ||||||||||||
| 51 | isa => 'ArrayRef', | ||||||||||||
| 52 | lazy_build => 1, | ||||||||||||
| 53 | ); | ||||||||||||
| 54 | |||||||||||||
| 55 | 1 | ▶ | sub _build_colours { | ||||||||||
|
Subroutine
_build_colours: called CC=1 SCAR=0.0
| |||||||||||||
| 56 | 2 | ▶ | no warnings 'qw'; # I know what I'm doing here! | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 57 | return [ | ||||||||||||
| 58 | 1 | map { "rgb($_)" } | |||||||||||
| 59 | qw( | ||||||||||||
| 60 | 0 | ||||||||||||
| 61 | 255,127,127 | ||||||||||||
| 62 | 127,255,127 | ||||||||||||
| 63 | 127,127,255 | ||||||||||||
| 64 | 255,255,127 | ||||||||||||
| 65 | 255,127,255 | ||||||||||||
| 66 | 127,255,255 | ||||||||||||
| 67 | ) | ||||||||||||
| 68 | ]; | ||||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | 2 | has +colour => ( | |||||||||||
| 72 | is => 'ro', | ||||||||||||
| 73 | isa => 'Str', | ||||||||||||
| 74 | lazy_build => 1, | ||||||||||||
| 75 | ); | ||||||||||||
| 76 | |||||||||||||
| 77 | 1 | ▶ | sub _build_colour { | ||||||||||
|
Subroutine
_build_colour: called CC=2 SCAR=7.2
| |||||||||||||
| 78 | 1 | my $self = shift; | |||||||||||
| 79 | 1 | ▶ | return $self->colours->[$self->generation] // 'rgb(127.127.127)'; | ||||||||||
|
Condition50%1/2
$self->colours->[$self->generation] // "rgb(127.127.127)"
MC/DC0%0/1
$self->colours->[$self->generation] // "rgb(127.127.127)"
$self->colours->[$self->generation]
Truth table50%1/2
A
A= $self->colours->[$self->generation]
| |||||||||||||
| 80 | } | ||||||||||||
| 81 | |||||||||||||
| 82 | =head1 METHODS AND ATTRIBUTES | ||||||||||||
| 83 | |||||||||||||
| 84 | =head2 BUILD | ||||||||||||
| 85 | |||||||||||||
| 86 | Called by Moose after the construction of a new object. This just updates | ||||||||||||
| 87 | the C<text> attribute to add the years of the person's birth and death. | ||||||||||||
| 88 | |||||||||||||
| 89 | =cut | ||||||||||||
| 90 | |||||||||||||
| 91 | 1 | ▶ | sub BUILD { | ||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||
| 92 | 1 | my $self = shift; | |||||||||||
| 93 | |||||||||||||
| 94 | 1 | my $text = $self->{text}; | |||||||||||
| 95 | |||||||||||||
| 96 | 1 | ▶ | if ($self->start) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 97 | 1 | $text .= ' (' . $self->start . ' - '; | |||||||||||
| 98 | 1 | ▶ | $text .= $self->end if $self->end; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 99 | 1 | $text .= ')'; | |||||||||||
| 100 | } | ||||||||||||
| 101 | |||||||||||||
| 102 | 1 | $self->{text} = $text; | |||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | =head2 set_index | ||||||||||||
| 106 | |||||||||||||
| 107 | Called by SVG::Timeline::Genealogical each time a new person is added to the | ||||||||||||
| 108 | timeline, this method works out where this person should appear in the | ||||||||||||
| 109 | timeline. | ||||||||||||
| 110 | |||||||||||||
| 111 | =cut | ||||||||||||
| 112 | |||||||||||||
| 113 | 1 | ▶ | sub set_index { | ||||||||||
|
Subroutine
set_index: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 114 | 1 | my $self = shift; | |||||||||||
| 115 | 1 | my ($count_of_people) = @_; | |||||||||||
| 116 | |||||||||||||
| 117 | 1 | my $den = 2 ** $self->generation; | |||||||||||
| 118 | 1 | my $num = 2 * ($self->ahnen - $den / 2) + 1; | |||||||||||
| 119 | |||||||||||||
| 120 | 1 | my $index = $count_of_people * ($num/$den); | |||||||||||
| 121 | |||||||||||||
| 122 | 1 | $self->{index} = $index; | |||||||||||
| 123 | } | ||||||||||||
| 124 | |||||||||||||
| 125 | =head1 AUTHOR | ||||||||||||
| 126 | |||||||||||||
| 127 | Dave Cross <dave@perlhacks.com> | ||||||||||||
| 128 | |||||||||||||
| 129 | =head1 COPYRIGHT AND LICENCE | ||||||||||||
| 130 | |||||||||||||
| 131 | Copyright (c) 2017, Magnum Solutions Ltd. All Rights Reserved. | ||||||||||||
| 132 | |||||||||||||
| 133 | This library is free software; you can redistribute it and/or modify it | ||||||||||||
| 134 | under the same terms as Perl itself. | ||||||||||||
| 135 | |||||||||||||
| 136 | =cut | ||||||||||||
| 137 | |||||||||||||
| 138 | 2 | 1; | |||||||||||