Class:...::Hash(3pm)

πŸ“¦
version 1.03 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 (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