ObjectTemplate(3pm) User Contributed Perl Documentation ObjectTemplate(3pm)NAME
Class::ObjectTemplate - Perl extension for an optimized template builder base class.
SYNOPSIS
package Foo;
use Class::ObjectTemplate;
require Exporter;
@ISA = qw(Class::ObjectTemplate Exporter);
attributes('one', 'two', 'three');
# initialize will be called by new()
sub initialize {
my $self = shift;
$self->three(1) unless defined $self->three();
}
use Foo;
$foo = Foo->new();
# store 27 in the 'one' attribute
$foo->one(27);
# check the value in the 'two' attribute
die "should be undefined" if defined $foo->two();
# set using the utility method
$foo->set_attribute('one',27);
# check using the utility method
$two = $foo->get_attribute('two');
# set more than one attribute using the named parameter style
$foo->set_attributes('one'=>27, 'two'=>42);
# or using array references
$foo->set_attributes(['one','two'],[27,42]);
# get more than one attribute
@list = $foo->get_attributes('one', 'two');
# get a list of all attributes known by an object
@attrs = $foo->get_attribute_names();
# check that initialize() is called properly
die "initialize didn't set three()" unless $foo->three();
DESCRIPTION
Class::ObjectTemplate is a utility class to assist in the building of other Object Oriented Perl classes.
It was described in detail in the O'Reilly book, "Advanced Perl Programming" by Sriram Srinivasam.
EXPORT
attributes(@name_list)
This method creates a shared setter and getter methods for every name in the list. The method also creates the class constructor, "new()".
WARNING: This method must be invoked within the module for every class that inherits from Class::ObjectTemplate, even if that class defines
no attributes. For a class defining no new attributes, it should invoke "attributes()" with no arguments.
AUTHOR
Original code by Sriram Srinivasam.
Fixes and CPAN module by Jason E. Stewart (jason@openinformatics.com)
SEE ALSO
http://www.oreilly.com/catalog/advperl/
perl(1).
Class::ObjectTemplate::DB
perl v5.12.4 2002-02-25 ObjectTemplate(3pm)
Check Out this Related Man Page
Class::Adapter::Builder(3pm) User Contributed Perl Documentation Class::Adapter::Builder(3pm)NAME
Class::Adapter::Builder - Generate Class::Adapter classes
SYNOPSIS
package My::Adapter;
use strict;
use Class::Adapter::Builder
ISA => 'Specific::API',
METHODS => [ qw{foo bar baz} ],
method => 'different_method';
1;
DESCRIPTION
"Class::Adapter::Builder" is another mechanism for letting you create Adapter classes of your own.
It is intended to act as a toolkit for generating the guts of many varied and different types of Adapter classes.
For a simple base class you can inherit from and change a specific method, see Class::Adapter::Clear.
The Pragma Interface
The most common method for defining Adapter classes, as shown in the synopsis, is the pragma interface.
This consists of a set of key/value pairs provided when you load the module.
# The format for building Adapter classes
use Class::Adapter::Builder PARAM => VALUE, ...
ISA The "ISA" param is provided as either a single value, or a reference to an "ARRAY" containing is list of classes.
Normally this is just a straight list of classes. However, if the value for "ISA" is set to '_OBJECT_' the object will identify itself
as whatever is contained in it when the "->isa" and "->can" method are called on it.
NEW Normally, you need to create your "Class::Adapter" objects separately:
# Create the object
my $query = CGI->new( 'param1', 'param2' );
# Create the Decorator
my $object = My::Adapter->new( $query );
If you provide a class name as the "NEW" param, the Decorator will do this for you, passing on any constructor arguments.
# Assume we provided the following
# NEW => 'CGI',
# We can now do the above in one step
my $object = My::Adapter->new( 'param1', 'param2' );
AUTOLOAD
By default, a "Class::Adapter" does not pass on any methods, with the methods to be passed on specified explicitly with the 'METHODS'
param.
By setting "AUTOLOAD" to true, the "Adapter" will be given the standard "AUTOLOAD" function to to pass through all unspecified methods
to the parent object.
By default the AUTOLOAD will pass through any and all calls, including calls to private methods.
If the AUTOLOAD is specifically set to 'PUBLIC', the AUTOLOAD setting will ONLY apply to public methods, and any private methods will
not be passed through.
METHODS
The "METHODS" param is provided as a reference to an array of all the methods that are to be passed through to the parent object as is.
Any params other than the ones specified above are taken as translated methods.
# If you provide the following
# foo => bar
# It the following are equivalent
$decorator->foo;
$decorator->_OBJECT_->bar;
This capability is provided primarily because in Perl one of the main situations in which you hit the limits of Perl's inheritance model is
when your class needs to inherit from multiple different classes that containing clashing methods.
For example:
# If your class is like this
package Foo;
use base 'This', 'That';
1;
If both "This->method" exists and "That->method" exists, and both mean different things, then "Foo->method" becomes ambiguous.
A "Class::Adapter" could be used to wrap your "Foo" object, with the "Class::Adapter" becoming the "That" sub-class, and passing
"$decorator->method" through to "$object->that_method".
METHODS
Yes, "Class::Adapter::Builder" has public methods and later on you will be able to access them directly, but for now they are remaining
undocumented, so that I can shuffle things around for another few versions.
Just stick to the pragma interface for now.
SUPPORT
Bugs should be reported via the CPAN bug tracker at
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-Adapter>
For other issues, contact the author.
AUTHOR
Adam Kennedy <adamk@cpan.org>
SEE ALSO
Class::Adapter, Class::Adapter::Clear
COPYRIGHT
Copyright 2005 - 2010 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
perl v5.10.1 2010-04-12 Class::Adapter::Builder(3pm)