The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Genealogy::AncestorChart - create a table of genealogical ancestors.

SYNOPSIS

    use Genealogy::AncestorChart;

    my @people = ($me, $dad, $mum, ...);

    my $chart = Genealogy::AncestorChart->new({
      people => \@people,
    });

    say $gac->chart;

DESCRIPTION

This module draws an HTML table which contains a representation of ancestors. For the first three generations, the table will look like this:

  +-------------+-------------+----------------+
  | Person      | Parents     | Grandparents   |
  +-------------+-------------+----------------+
  | 1: Person   | 2: Father   | 4: Grandfather |
  |             |             +----------------+
  |             |             | 5: Grandmother |
  |             +-------------+----------------+ 
  |             | 3: Mother   | 6: Grandfather |
  |             |             +----------------+
  |             |             | 7: Grandmother |
  +-------------+-------------+----------------+ 

The labels inside the table are generated from the array of people that is passed into the constructor when the object is created.

METHODS

new(\%options)

The constructor method. Builds a new instance of the class and returns that object. Takes a hash reference containing various parameters.

  • people

    This is the only mandatory option.

    This should be a reference to a hash of objects. The key in the hash should be an "Ahnentafel number" (see below) and the value should be an object will represent one person to be displayed in the output. The text displayed for each person is retrieved by calling a method on the relevant object. The default method name is display_name, but this can be changed using the label_method option, described below.

    These objects can be of any class - as long as they have a method of the correct name that returns a text string that can be used in the table output to identify the person in question.

    The keys in the hash should be "Ahnentafel numbers". This is a series of positive integers that genealogists use to identify the ancestors of an individual. The person of interest is given the number 1. Their father and mother are 2 and 3, respectively. Their grandparents are numbers 4 to 7 in the order father's father, father's mother, mother's father and mother's mother. These numbers have the property that if you know the number of a person in the hash, then you can get the number of their father by doubling their number. Similarly, you can get the number of their mother by doubling their number and adding one.

    Because of the nature of the table that is produced, the number of people in your array should be one less than a power of two (i.e. 1, 3, 7, 15, 31, 63, etc.) For any any other number, a table will still be produced, but it won't be guaranteed to be valid HTML.

    In the future, I might introduce a "strict" mode that only allows a valid number of people in the array.

  • label_method

    This is the name of the method that should be called on the objects in the "people" array. The default value is display_name.

  • headers

    An array reference containing the list of titles that are used for the first few columns in the table. The default list is 'Person', 'Parents', 'Grandparents' and 'Great Grandparents'. You might want to override this if, for example, you want the output in a different language.

  • extra_headers

    A string containing the basis for an extra headers that are required after the fixed list stored in headers. In English, we use the terms 'Great Great Grandparents', 'Great Great Great Grandparents' and so on. So the default value for this string is 'Gt Grandparents'. This is prepended with an incrementing string (which starts at 2) so we get the strings '2 Gt Grandparents', '3 Gt Grandparents', and so on.

    You might want to override this if, for example, you want the output in a different language.

num_people

Returns the number of people in the list of people.

num_rows

Returns the number of rows that will be in the table. This is calculated from the list of people.

It is unlikely that you will need to call this method.

rows

Returns the list of rows that will be used to create the table.

It is unlikely that you will need to call this method.

row_range

Returns a start and end point that is used in creating the rows of the table.

It is unlikely that you will need to call this method.

num_cols

Returns the number of columns that will be in the table. This is calculated from the list of people.

It is unlikely that you will need to call this method.

row

Returns the HTML that makes up one row in the table.

It is unlikely that you will need to call this method.

table_headers

Calculates and returns the headers used in the table.

chart

Returns the complete HTML of the ancestor chart.

AUTHOR

Dave Cross <dave@perlhacks.com>

COPYRIGHT AND LICENCE

Copyright (c) 2022, Magnum Solutions Ltd. All Rights Reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.