Class:...::Array(3pm)

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

πŸ’– NAME πŸ’–

Class::Gomor::Array β€” a class and object builder, but make it the array version πŸ“

(and yeah bestie, this is the perl manual page for Class:...::Array(3pm), straight out of the User Contributed Perl Documentation section β€” she's a real one, fr)


✨ SYNOPSIS ✨

okay so here's the whole vibe, copy-paste blessed:

# Create a base class in BaseClass.pm
package My::BaseClass;

require Class::Gomor::Array;
our @ISA = qw(Class::Gomor::Array);

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 indices and accessors
My::BaseClass->cgBuildIndices;
My::BaseClass->cgBuildAccessorsScalar(\@AS);
My::BaseClass->cgBuildAccessorsArray(\@AA);

sub other {
   my $self = shift;
   @_ ? $self->[$self->cgGetIndice('other')] = [ split(/\n/, shift) ]
      : @{$self->[$self->cgGetIndice('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->cgBuildIndices;
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', ]);

🌈 DESCRIPTION 🌈

So like β€” this class is a subclass from Class::Gomor. That's the whole origin story πŸ’… She implements objects as array references, and she inherits all her methods from Class::Gomor. That's it, that's the tea.


πŸ¦‹ GLOBAL VARIABLES πŸ¦‹

See Class::Gomor. (she said "go read the other one" and honestly? valid.)


πŸ‘‘ METHODS πŸ‘‘

new (hash)

The object constructor, the birth of your baby ✨ This is where the attributes you pass in (as a hash argument) get checked against the valid attributes β€” and those valid ones are gathered by the cgGetAttributes method. What counts as valid? Attributes that actually exist (doh!), and that don't have an undef value. Checking is the default behavior, bestie. You can dodge it by setting the $NoCheck global variable (go see perldoc Class::Gomor for that).

cgBuildIndices

You MUST call this method one time at the beginning of your classes β€” and all subclasses too, even if you're not adding any new attributes, no exceptions πŸ™…β€β™€οΈ It builds the matching between object attributes and their indices inside the array object. Global variables get created in your class, and they look like this: $__attributeName.

cgBuildAccessorsScalar (array ref)

cgBuildAccessorsArray (array ref)

See Class::Gomor. (yeah, both of them, same energy πŸ’œ)

cgGetIndice (scalar)

Returns the array indice of the attribute you hand it as a parameter. Use this in your own programs so you don't have to call the global variable directly to get indice info about the object you're asking about β€” which means you can dodge using no strict 'vars'; entirely, iconic. This method usually gets used when you build your own accessors (the ones using attributes defined in @AO).

cgClone [ (scalar) ]

Wanna clone one of your objects? Just call this method 🫢 There's an optional parameter you can pass to create multiple clones. Heads up though: cloning only happens on the first level attributes β€” so if you've got attributes holding other objects, bestie, those are not getting cloned.

cgFullClone [ (scalar) ]

Same deal as cgClone, but this one clones all attributes recursively β€” but only if they are subclassed from Class::Gomor. So objects made with modules other than Class::Gomor::Array or Class::Gomor::Hash? Not cloned. Sorry babe.

Another thing to note: there is no catch for cycling references (that's when you link two objects to each other 😭). You have been warned. πŸ”₯

for real, she said you've been warned. that's not me being dramatic, that's the manual.

cgDumper

Returns a string, exactly like the Data::Dumper Dumper method does. Super useful for debugging, because an arrayref object doesn't include attribute names β€” so this is your girl when you're like "wait which one was which πŸ’€".


🌸 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.


k that's the whole page bestie, go build some objects πŸ’…

this was perl v5.36.0, dated 2022-10-13, from the Class:...::Array(3pm) manual page β€” love that for us βœ¨πŸ¦‹

πŸ“¦ where this page comes from