SWISS::BaseClass(3pm)
π SWISS::BaseClass π
okay bestie, so this is SWISS::BaseClass(3pm) from the User Contributed Perl Documentation corner of the world, and it's literally the blueprint for every class that wants to feel like it inherited stuff properly. no cap. π«Ά
β¨ NAME β¨
SWISS::BaseClass β the base class of your dreams, bestie. she's giving foundation. she's giving main character energy for your whole inheritance tree. π
πΈ DESCRIPTION πΈ
This class is designed to impliment many of the properties that you expect in inheritance. (yes, "impliment", she said what she said, we're leaving it π ) All the housekeeping functions are defined in this module. See the notes on use for a description of how to make use of it.
π¦ Functions π¦
new
Returns a new SWISS::BaseClass object. baby's first object. iconic behavior. β¨
rebless
Converts a base class into your class! Call as $self->rebless($class) where $self is a base class object. It returns $self, reblessed, with the correct member variables.
it's giving glow-up. it's giving transformation arc. π§
initialize
Override this in each derived class to provide class specific initialization. For example, initialize may put arrays into member variables that need them. You must provide an initialize function.
fr fr, bestie, this one is not optional. the base class will simply not have your back here. you gotta write it. π
reformat
Some line objects are implementing "lazy writing". This means that on writing an entry, they are only reformatted if they have been modified. The method reformat forces an object to be reformatted even if its content has not been modified. This may be useful e.g. to make sure the current formatting rules are applied.
she's like "no babe we're not doing lazy today, we're doing the WORK." π₯
setEvidenceTags @array
Sets the evidence tags of the object to the list passed in @array.
addEvidenceTag string
Adds the evidence tag to the object.
deleteEvidenceTag string
Deletes the evidence tag from the object.
hasEvidenceTag string
returns true if the object has the evidence tag.
getEvidenceTags
returns the array of evidence tags of the object
Check4Clashes
This function checks your classes member variable list for clashes with any class that it inherits from (any class that can(_containsFields) returns true on!). If it detects that in any base class that any data members have been already defined, it dies with a listing of the variables already used.
π yeah it literally dies. like, exits. like, the drama is real. but she's doing it for your own good bestie, promise.
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.
like she does a full sweep of the family tree and reports every single problematic cousin. no one escapes the vibe check. π
_containsFields
This function is responsible for comparing a classes fields with the set in the calling package. This implimentation will work for cases where all of the classes that contribute fields are derived from SWISS::BaseClass. You may wish to make your own class fit this interface, so what follows is an interface API.
_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
}
it's giving "recursive queen". she checks herself, then she checks her parents, then her parents check their parents. generational. π
equal
If two objects are equal, it returns true.
β οΈ Warning: This funktion compares two objects using a simple dump in Perl format, seeData::Dumpermodule. 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.
so like, a true is a promise, but a false is just... a maybe? she's an overachiever with trust issues and honestly? same. π
copy
Returns a "deep copy" of the object.
no shallow copies in this house. we go ALL the way down. periodt. π
π A skeletal derived class π
here's the blueprint bestie, copy it, love it, make it yours:
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!
okay and that's genuinely it. that's the whole vibe. go forth and inherit responsibly, bestie π«ΆπΈ
this little love letter was brought to you by perl v5.32.1, dated 2021-08-15, in the SWISS::BaseClass(3pm) era β and yes she ATE. π
β¨π
π¦ where this page comes from
- debian bookworm: libswiss-perl 1.80-1 Β· GPL-2.0-or-later
- debian trixie: libswiss-perl 1.80-1 Β· GPL-2.0-or-later
- ubuntu jammy: libswiss-perl 1.80-1 Β· GPL-2.0-or-later
- ubuntu noble: libswiss-perl 1.80-1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms