SWISS::BaseClass(3pm) | User Contributed Perl Documentation | SWISS::BaseClass(3pm) |
SWISS::BaseClass
This class is designed to impliment many of the properties that you expect in inheritance. All the housekeeping functions are defined in this module. See the notes on use for a description of how to make use of it.
It stops searching a root of an inheritance hierachy when it can find no baseclasses that support _containsFields. It will find all clashes in an entire inheritance tree.
So in the inheritance hierachy of
SWISS::BaseClass -> A -> B -\ > E SWISS::BaseClass -> C -> D -/
where E is the most derived class, if E contains names that clash with A members and names that clash with B members, both the A and B member clashes will be reported.
If there were clashes with B and C, say, then again, all of the clashes would be reported.
_containsFields assumes that the first argument is the package that it is being called in. The following arguments are taken to be a list of fields which to check are not found in members of the current package.
It should return either "undef" or a reference to an array of name clashes in the format "package::variable". It should call it's self for each parental class that supports this function.
So it would look something like
_containsFields {
my $class = shift;
my @toCheck = @_;
foreach @toCheck { check that they are not in me. If they are, add them to the list of clashes to return. } add all base class clashes to your list of clashes if there were name clashes return a reference to them otherwise return undef }
Warning: This funktion compares two objects using a simple dump in Perl format, see Data::Dumper module. The comparison also takes private variables into account. Therefore: If the method 'equal' returns true, the objects are guaranteed to be equal, but it might return false although the two objects are equal in they public attributes.
package myDerived; use vars qw ( @ISA %fields ); BEGIN { @ISA = ('SWISS::BaseClass'); %fields = ( 'i' => 1, 'hash' => undef ); myDerived->check4Clashes(); } sub new { print "myDerived::new(@_)\n"; my $class = shift; my $self = new SWISS::BaseClass; $self->rebless ($class); return $self; } sub initialize { my $self = shift; $self->{'hash'} = {}; }
A class derived from myDerived would just substitute the name myDerived for SWISS::BaseClass. Hey presto - all sorted!
2021-08-15 | perl v5.32.1 |