Class and object builder, array version
# 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', ]);
This class is a subclass from Class::Gomor. It implements objects as array references, and inherits methods from Class::Gomor.
See Class::Gomor.
Object constructor. This is where user passed attributes (hash argument) are checked against valid attributes (gathered by cgGetAttributes method). Valid attributes are those that exists (doh!), and have not an undef value. The default is to check this, you can avoid it by setting $NoCheck global variable (see perldoc Class::Gomor).
You \s-1MUST\s0 call this method one time at the beginning of your classes, and all subclasses (even if you do not add new attributes). It will build the matching between object attributes and their indices inside the array object. Global variables will be created in your class, with the following format: $_\|_attributeName.
See Class::Gomor.
Returns the array indice of specified attribute passed as a parameter. You can use it in your programs to avoid calling directly the global variable giving indice information concerning requesting object, thus avoiding using `no strict 'vars';'. This method is usually used when you build your own accessors (those using attributes defined in @AO).
You can clone one of your objects by calling this method. An optional parameter may be used to create multiple clones. Cloning will occure only on the first level attributes, that is, if you have attributes containing other objects, they will not be cloned.
This method is the same as cgClone, but will clone all attributes recursively, but only if they are subclassed from Class::Gomor. So, objects created with other modules than Class::Gomor::Array or Class::Gomor::Hash will not be cloned. Another thing to note, there is no catch for cycling references (when you link two objects with each others). You have been warned.
Will return a string as with Data::Dumper Dumper method. This is useful for debugging purposes, because an arrayref object does not include attributes names.
Class::Gomor
Patrice <GomoR> Auffret
Copyright (c) 2004-2009, Patrice <GomoR> Auffret
You may distribute this module under the terms of the Artistic license. See \s-1LICENSE\s0.Artistic file in the source distribution archive.