Class::Gomor::Hash3pm
Class and object builder, hash version
Synposis
# Create a base class in BaseClass.pmpackage 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 attributessub new { shift->SUPER::new(attribute3 => [], attribute4 => [], @_) }# Create accessorsMy::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.pmpackage 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 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 hash references, and inherits methods from Class::Gomor.
Global variable
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-
This method does nothing. It only exists to make it more easy to switch between
Class::Gomor::ArrayandClass::Gomor::Hash.
cgBuildAccessorsScalar(array ref)
cgBuildAccessorsArray(array ref)-
See
Class::Gomor.
cgGetIndice(scalar)-
This method does nearly nothing. It only returns the passed-in scalar parameter (so the syntax is the same as in
Class::Gomor::Array). It only exists to make it more easy to switch betweenClass::Gomor::ArrayandClass::Gomor::Hash.
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 less useful for hashref objects, because they already 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.