Class-GAPI
view release on metacpan or search on metacpan
<pre>
my $pet = SpyGuppy->new() ;
$pet->CBC->something() ;
$pet->DES->somethingelse() ;</pre>
<p>@Children also conveiniently has 2 special class names. Class::GAPI::Foo, and Class::List::Foo. In
this case ``Foo'' can be anything you like, and will correspondingly be used to create a
sprout()ed object. Note that Class::GAPI::Foo is a a sprouted hash, while Class::List::Foo
is a sprouted array. This is very convenient for making lists of objects. The technique below can be used
to quickly create a variety of styles of record manager classes.</p>
<pre>
package Guppy::School ;
use Guppy ;
our @ISA = qw(Guppy) ; # We are derived from a Guppy, which is derived from a GAPI
our @Children = qw(Class::List::School) ; # $self->{'School'} is now an array</pre>
<pre>
sub doSpawn { # Add a new Guppy Object
my $self = shift ;
my $fish = Guppy->new() ;
push @{$self->School()}, $fish ;
}</pre>
<pre>
sub fishNet { # Get a specific Guppy object
my $self = shift ;
my $n = shift ;
my $fish = $self->School->[$n] ;
return($fish) ;
}
1 ;</pre>
<p>The third stage of initialization is by defining a local &_init subroutine. This gets called after everything else. So if one desires to
do something with passed variables after the class is blessed, this is where to do it. If you call an autoloaded function here, it takes place
after autoloaded functions from ->new(), and Default_Properties. So you do have access to data passed or processed during invokation.</p>
<p>passed at invokation:</p>
<pre>
package Guppy ;
use Class::GAPI ;
our @ISA = (Class::GAPI);
use strict ;
sub _init {
my $self = shift ;
$self->chopchopchop() if $self->sushi() && $self->filet() ;
}
1 ;</pre>
<pre>
package PetShop ;
use Guppy ;</pre>
<pre>
my $pet = Guppy->new(-sushi => 0, -filet => undef) ;
my $lunch = Guppy->new(-sushi => 1, -filet => 1) ;</pre>
<p>In this case the execution of method chopchopchop would occur
in the case of lunch but not in the case of pet.</p>
<p>
</p>
<hr />
<h1><a name="other_functions">OTHER FUNCTIONS</a></h1>
<p>Cloning is supported for Class::GAPI objects and any subordinate objects based on Class::GAPI
or that Inherit Class::GAPI. This includes Class::List objects. This is function is eval()d, so it
will not crash if you have other stuff in their, just don't expect that other stuff copy.</p>
<pre>
my $twin = $pet->clone(); # Make the FDA nervous</pre>
<p>The <code>overlay()</code> function allows one to execute a block of functions by passing hash. This is equivilant
to what happens when constructed with new(). This is typically usefull when you want to copy a hash
into several objects as you might in a record table:</p>
<pre>
package Guppy::School ;
use Guppy ;
our @ISA = qw(Guppy) ; # We are derived from a Guppy, which is derived from a GAPI
our @Children = qw(Class::List::School) ; # $self->{'School'} is now an array</pre>
<pre>
sub doSpawn { # Add a new Guppy Object
my $self = shift ;
my $fish = Guppy->new(@_) ; # Pass options pairs to the new fish
push @{$self->School()}, $fish ;
}</pre>
<pre>
sub fishGrow { # Add a block of options like so: fishGrow(2, foo => 'bar') ;
my $self = shift ;
my $n = shift ;
$self->School->[$n]->overlay(@_);
return($fish) ;
}
1 ;</pre>
<p>The <code>warn_self()</code> function is pretty much what it sounds like. You can call it at any level with
a tree of nested GAPI and it will produce a table of the object as a warning. Obviously this
handy for debugging:</p>
<pre>
$self->warn_self() ;
$self->Foo->Bar->warn_self() ;</pre>
<p>
</p>
<hr />
<h1><a name="notes">NOTES</a></h1>
<p>It is worth noting that GAPI uses a lot of <code>eval()</code> calls. So it is fairly slow. Also special
care should be given to using this module in CGI because of that. You should probably
read the code and understand how the constructor works before even considering using this
thing in cgi code. Consider yourself warned.</p>
<p>This was written on an Win32 box running cygwin and Activestate, and it works on both with Perl 5.8.
I expect it should work with anything later than 5.6.1, but It hasn't been tested.</p>
<p>Autoloaded methods tend to cause silent failure modes. Essentailly typos that would have
normally crashed perl will often just end up creating a dangling property somewhere.
Use $self-><code>warn_self()</code> to take snapshots of objects if something is not getting properly
populated. If you see two similarly named properties, you've found the culprit.</p>
<p>No animals were harmed in the development of this module.</p>
<p>
</p>
<hr />
<h1><a name="author">AUTHOR</a></h1>
<p>Matthew Sibley
<a href="mailto:matt@itoperators.com">matt@itoperators.com</a></p>
<p>
</p>
<hr />
<h1><a name="copyright_and_licence">COPYRIGHT AND LICENCE</a></h1>
<p>Copyright (C) 2005 IT Operators <A HREF="http://www.itoperators.com">http://www.itoperators.com</A></p>
<p>This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.6 or,
at your option, any later version of Perl 5 you may have available.</p>
</body>
</html>
( run in 0.675 second using v1.01-cache-2.11-cpan-5837b0d9d2c )