Class::Gomor::Array3pm
Class and object builder, array version
Synposis
# Create a base class in BaseClass.pmpackage 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 attributessub new { shift->SUPER::new(attribute3 => [], attribute4 => [], @_) }# Create indices and accessorsMy::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.pmpackage 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 classesmy $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', ]);
Overview
This class is a subclass from Class::Gomor. It implements objects as array references, and inherits methods from Class::Gomor.
Global variables
See Class::Gomor.
Methods
new(hash)-
Object constructor. This is where user passed attributes (hash argument) are checked against valid attributes (gathered by
cgGetAttributesmethod). 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$NoCheckglobal variable (see perldocClass::Gomor).
cgBuildIndices-
You MUST 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.
cgBuildAccessorsScalar(array ref)
cgBuildAccessorsArray(array ref)-
See
Class::Gomor.
cgGetIndice(scalar)-
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).
cgClone[ (scalar) ]-
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.
cgFullClone[ (scalar) ]-
This method is the same as
cgClone, but will clone all attributes recursively, but only if they are subclassed fromClass::Gomor. So, objects created with other modules thanClass::Gomor::ArrayorClass::Gomor::Hashwill 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.
cgDumper-
Will return a string as with
Data::DumperDumper method. This is useful for debugging purposes, because an arrayref object does not include attributes names.
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.
Releases
8 releases since Debian 6.0 (Squeeze); the text changed 2 times.