GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  CLASS::GOMOR::HASH (3)

.ds Aq ’

NAME

Class::Gomor::Hash - class and object builder, hash version

CONTENTS

SYNPOSIS



   # 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, ]);



DESCRIPTION

This class is a subclass from <B>Class::GomorB>. It implements objects as hash references, and inherits methods from <B>Class::GomorB>.

GLOBAL VARIABLE

See <B>Class::GomorB>.

METHODS

<B>newB> (hash) Object constructor. This is where user passed attributes (hash argument) are checked against valid attributes (gathered by <B>cgGetAttributesB> 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 <B>B>$NoCheck<B>B> global variable (see perldoc <B>Class::GomorB>).
<B>cgBuildIndicesB> This method does nothing. It only exists to make it more easy to switch between <B>Class::Gomor::ArrayB> and <B>Class::Gomor::HashB>.
<B>cgBuildAccessorsScalarB> (array ref)
<B>cgBuildAccessorsArrayB> (array ref) See <B>Class::GomorB>.
<B>cgGetIndiceB> (scalar) This method does nearly nothing. It only returns the passed-in scalar parameter (so the syntax is the same as in <B>Class::Gomor::ArrayB>). It only exists to make it more easy to switch between <B>Class::Gomor::ArrayB> and <B>Class::Gomor::HashB>.
<B>cgCloneB> [ (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.
<B>cgFullCloneB> [ (scalar) ] This method is the same as <B>cgCloneB>, but will clone all attributes recursively, but only if they are subclassed from <B>Class::GomorB>. So, objects created with other modules than <B>Class::Gomor::ArrayB> or <B>Class::Gomor::HashB> 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.

<B>cgDumperB> Will return a string as with <B>Data::DumperB> Dumper method. This is less useful for hashref objects, because they already include attributes names.

SEE ALSO

Class::Gomor

AUTHOR

Patrice <GomoR> Auffret

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.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 CLASS::GOMOR::HASH (3) 2015-01-13

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.