Gedcom::Item(3pm) | User Contributed Perl Documentation | Gedcom::Item(3pm) |
Gedcom::Item - a base class for Gedcom::Grammar and Gedcom::Record
Version 1.22 - 15th November 2019
use Gedcom::Record; $item->{grammar} = Gedcom::Grammar->new(file => $item->{grammar_file}, callback => $item->{callback}); my $c = $item->copy; $item->read if $item->{file}; $item->add_items($rec); while (my $next = $item->next_item($item)) my $line = $item->next_line; my $line = $item->next_text_line; $item->write($fh, $level, $flush); $item->write_xml($fh, $level); $item->print; my $item = $item->get_item("CHIL", 2); my @items = $item->get_item("CHIL"); my $parent = $item->parent; my $success = $item->delete; $item->delete_item($sub_item); my $v = $item->level; $item->level(1); my $v = $item->xref; my $v = $item->tag; my $v = $item->value; my $v = $item->pointer; my $v = $item->min; my $v = $item->max; my $v = $item->gedcom; my $v = $item->file; my $v = $item->line; my $v = $item->full_value; my $sub_items = $item->_items; my @sub_items = $item->items; $item->delete_items;
A selection of subroutines to handle items in a GEDCOM file.
Some of the more important hash members are:
The level of the item.
The cross reference, either hard or soft.
The name of the tag.
The value of the item.
True iff the value is a pointer to another item.
The minimum number of items allowed.
The maximum number of items allowed.
The top level Gedcom object.
The file from which this object was read, if any.
The line number from which this object was read, if any.
Array of all sub-items of this item.
It should not be necessary to access these hash members directly.
$item->{grammar} = Gedcom::Grammar->new(file => $item->{grammar_file}, callback => $item->{callback});
Create a new object.
If file is supplied, it is the name of a file to read.
If callback is supplied, it is a subroutine reference which is called at various times while the file is being read.
The subroutine takes five parameters:
$title: A title
$txt1: One text message
$txt2: A secondary text message
$current: A count of how far through the file we are
$total: The extent of the file
The subroutine should return true iff the file should continue to be read.
my $c = $item->copy;
Make a copy of the object. The sub-items are copied too.
$item->read if $item->{file};
Read a file into the object. Called by the constructor.
$item->add_items($rec);
Read in the sub-items of a item.
while (my $next = $item->next_item($item))
Read the next item from a file. Return the item or false if it cannot be read.
my $line = $item->next_line;
Read the next line from the file, and return it or false.
my $line = $item->next_text_line;
Read the next line of text from the file, and return it or false.
$item->write($fh, $level, $flush);
Write the item to a FileHandle.
The subroutine takes three parameters:
$fh: The FileHandle to which to write
$level: The level of the item
$flush: Whether or not to indent the GEDCOM output
according to the level
$item->write_xml($fh, $level);
Write the item to a FileHandle as XML.
The subroutine takes two parameters:
$fh: The FileHandle to which to write
$level: The level of the item
Note that this function is experimental. Please read the warnings for Gedcom::write_xml().
$item->print;
Print the item. Used for debugging. (What? There are bugs?)
my $item = $item->get_item("CHIL", 2); my @items = $item->get_items("CHIL");
Get specific sub-items from the item.
The arguments are the name of the tag, and optionally the count, starting from one.
In scalar context, returns the sub-item, or undef if it doesn't exist. In array context, returns all sub-items matching the specified tag.
NOTE - This function is deprecated - use get_item instead
my $child = get_child("CHIL2");
Get a specific child item from the item.
The argument contains the name of the tag, and optionally the count, starting from one. The regular expression to generate the tag and the count is:
my ($tag, $count) = $t =~ /^_?(\w+?)(\d*)$/
Returns the child item, or undef if it doesn't exist
NOTE - This function is deprecated - use get_item instead
my @children = get_children("CHIL");
my $parent = $item->parent;
Returns the parent of the item or undef if there is none.
Note that this is an expensive function. A child does not know who its parent is, and so this function searches through all items looking for one with the appropriate child.
my $success = $item->delete;
Deletes the item.
Note that this is an expensive function. It use parent() described above. It is better to use $parent->delete_item($child), assuming that you know $parent.
Note too that this function calls delete_item(), so its caveats apply.
$item->delete_item($sub_item);
Delete the specified sub-item from the item.
Note that this function doesn't do any housekeeping. It is up to you to ensure that you don't leave any dangling pointers.
my $v = $item->level; $item->level(1); my $v = $item->xref; my $v = $item->tag; my $v = $item->value; my $v = $item->pointer; my $v = $item->min; my $v = $item->max; my $v = $item->gedcom; my $v = $item->file; my $v = $item->line;
Return the eponymous hash element. If a value if passed into the function, the element is first assigned that value.
my $v = $item->full_value;
Return the value of the item including all CONT and CONC lines. This is probably what you want most of the time, and is the function called by default from other functions that return values. If, for some reason, you want to process CONT and CONC items yourself, you will need to use the value() function and probably the items() function.
my $sub_items = $item->_items;
Return a reference to a list of all the sub-items, reading them from the GEDCOM file if they have not already been read.
It should not be necessary to use this function. See items().
my @sub_items = $item->items;
Return a list of all the sub-items, reading them from the GEDCOM file if they have not already been read.
In general it should not be necessary to use this function. The sub-items will usually be accessed by name. This function is only necessary if the ordering of the different items is important. This is very rare, but is needed for example, when processing CONT and CONC items.
$item->delete_items;
Delete all the sub-items, allowing the memory to be reused. If the sub-items are required again, they will be reread.
It should not be necessary to use this function unless you are using read_only mode and need to reclaim your memory.
2019-11-21 | perl v5.30.0 |