NAME
Inheritance - Perl module for OO data inheritance
SYNOPSIS
use Inheritance qw(&bequeath &inherit);
$self = new Inheritance;
inherit($self [, $classname] [, $ignore]);
bequeath($self [, $classname] [, $overlay]);
DESCRIPTION
This is meant to be the class by which all future Perl data inheritance is carried out. I hope it will be to data inheritance what Exporter is to data/function exporting. This module has a minimal amount of coding for the maximal amount of usefulness.
The Inheritance class is derived from Tie::Hash::Overlay, and the constructor function is not overridden, so see Tie::Hash::Overlay(3) for the format of new().
The inherit() function reads the @ANCESTORS array in the class and runs inherit() and bequeath() for each element. The first argument should be the object to be modified (which had been previously returned by new Inheritance). If you pass $classname, it will be used as the name of the class to retrieve @ANCESTORS from instead of the value returned by (caller())[0]
. The $ignore parameter should be an array ref containing a list of classes that should not be accessed if found in an @ANCESTORS array. This argument is modified, to prevent infinite recursion within inherit(). If a class' own name is found in its @ANCESTORS array, tie(%hash, $class, $self);
is run, with \%hash being passed as the third argument to bequeath().
The bequeath() function has the important job. It reads the @BEQUEST array and uses the elements as the names of the other arrays that should be searched to find the names of the member variables. If no @BEQUEST variable is defined in the class, it is defaulted to qw(@PUBLIC @PROTECTED)
. If an array element in @BEQUEST isn't an array-name, it is assumed to be the name of a member variable.
If the $classname argument is passed, it will be used as the class-name to be worked on instead of (caller())[0]
. The $overlay argument is a hash that will be accessed to gain the value of member variables. The $overlay argument is passed directly to the Tie::Hash::Static constructor, so read Tie::Hash::Static(3).
AUTHOR
Ashley Winters <jql@accessone.com>
SEE ALSO
perl(1), perltie(1), perlref(1), Tie::Hash::Static(3), Tie::Hash::Overlay(3).