Class:...::Hash(3pm)
π Class::Gomor::Hash π
okay bestie, gather round, because this is the perl page for Class::Gomor::Hash β the class and object builder, hash version π
it's shipped with perl v5.36.0 in the User Contributed Perl Documentation family, and it is genuinely iconic for anyone who wants objects that are hashrefs. no cap.
β¨ SYNPOSIS β¨
here's the whole vibe, fr fr β a base class, a subclass, and a lil program that uses them:
# Create a base class in BaseClass.pm
package My::BaseClass;
require Class::Gomor::Hash;
our @ISA = qw(Class::Gomor::Hash);
our @AS = qw(attribute1 attribute2);
our @AA = qw(attribute3 attribute4);
our @AO = qw(other);
# You should initialize yourself array attributes
sub new { shift->SUPER::new(attribute3 => [], attribute4 => [], @_) }
# Create accessors
My::BaseClass->cgBuildAccessorsScalar(\@AS);
My::BaseClass->cgBuildAccessorsArray(\@AA);
sub other {
my $self = shift;
@_ ? $self->{'other'} = [ split(/\n/, shift) ]
: @{$self->{'other'}};
}
1;
# Create a subclass in SubClass.pm
package My::SubClass;
require My::BaseClass;
our @ISA = qw(My::BaseClass);
our @AS = qw(subclassAttribute);
My::SubClass->cgBuildAccessorsScalar(\@AS);
sub new {
shift->SUPER::new(
attribute1 => 'val1',
attribute2 => 'val2',
attribute3 => [ 'val3', ],
attribute4 => [ 'val4', ],
other => [ 'none', ],
subclassAttribute => 'subVal',
);
}
1;
# A program using those classes
my $new = My::SubClass->new;
my $val1 = $new->attribute1;
my @values3 = $new->attribute3;
my @otherOld = $new->other;
$new->other("str1\nstr2\nstr3");
my @otherNew = $new->other;
print "@otherNew\n";
$new->attribute2('newValue');
$new->attribute4([ 'newVal1', 'newVal2', ]);
like, that's the whole flow π¦ copy it, run it, feel it.
πΈ DESCRIPTION πΈ
so this class is a subclass from Class::Gomor β¨ it implements objects as hash references, and it inherits methods from Class::Gomor. that's it, that's the tea π
π GLOBAL VARIABLE π
lowkey just go see Class::Gomor. that's where the globals live. iykyk π
π METHODS π
new (hash)
the object constructor, the main character π₯ this is where the attributes you passed in (as a hash argument) get checked against the valid attributes β which get gathered up by the cgGetAttributes method. and what counts as valid? attributes that actually exist (doh!) and that don't have an undef value π
checking is the default behaviour. you can dodge it by setting the $NoCheck global variable (go read perldoc Class::Gomor for that one, bestie).
cgBuildIndices
this method does nothing π like, literally nothing. it only exists so it's easier to swap between Class::Gomor::Array and Class::Gomor::Hash. that's its whole job and honestly? respect. periodt β¨
cgBuildAccessorsScalar (array ref)
cgBuildAccessorsArray (array ref)
both of these? go see Class::Gomor π«Ά
cgGetIndice (scalar)
this one nearly does nothing β it just returns the scalar parameter you handed it. the reason is so the syntax stays the same as in Class::Gomor::Array π it only exists to make switching between Class::Gomor::Array and Class::Gomor::Hash easier. cute, right?
cgClone [ (scalar) ]
want to clone one of your objects? just call this π§ you can optionally pass a parameter to create multiple clones π
heads up though: cloning only happens on the first level attributes. so if you've got attributes holding other objects, those do not get cloned. no cap. π
cgFullClone [ (scalar) ]
basically cgClone's overachieving sibling β same thing, but it clones all attributes recursively π
β¦but only if they are subclassed from Class::Gomor. so objects built with modules other than Class::Gomor::Array or Class::Gomor::Hash will not be cloned. nope. not today. π
β οΈ also another thing to note: there is no catch for cycling references (you know, when you link two objects to each other) π you have been warned, bestie. seriously.
cgDumper
returns a string, exactly like Data::Dumper's Dumper method β¨ for the record though, this is less useful for hashref objects β because they already include the attribute names. so it's givingβ¦ redundant, but make it fashion π
π¦ SEE ALSO π¦
Class::Gomor
π AUTHOR π
Patrice <GomoR> Auffret π
π COPYRIGHT AND LICENSE π
Copyright (c) 2004-2015, Patrice <GomoR> Auffret
You may distribute this module under the terms of the Artistic license. See LICENSE.Artistic file in the source distribution archive. π
and that's the whole page, bestie π«Ά this was perl v5.36.0, dated 2022-10-13 β slay πβ¨ go build some hashref objects, you've absolutely got this πΈπ
π¦ where this page comes from
- ubuntu noble: libclass-gomor-perl 1.03-3 Β· Artistic-1.0-Perl
- ubuntu resolute: libclass-gomor-perl 1.03-3 Β· Artistic-1.0-Perl
- ubuntu stonking: libclass-gomor-perl 1.03-3 Β· Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms