Class::ObjectTemplate:DB - Perl extension for an optimized template builder base class with lookup capability.
package Foo; use Class::ObjectTemplate::DB; require Exporter; @ISA = qw(Class::ObjectTemplate:DB Exporter); attributes(lookup => ['one', 'two'], no_lookup => ['three']); $foo = Foo->new(); # these two invocations can trigger lookup $val = $foo->one(); $val = $foo->two(); # this invocation will not trigger lookup $val = $foo->three(); # undefined() handles lookup sub Foo::undefined { my ($self,$attr) = @_; # we retrieve $attr from DB return DB_Lookup($self,$attr); }
Class::ObjectTemplate::DB extends Class::ObjectTemplate in one simple way: the undefined() method.
undefined()
When a class that inherits from Class::ObjectTemplate::DB defines a method called undefined(), that method will be triggered when an attribute\'s getter method is invoked and the attribute\'s current value is undef.
undef
The author finds this useful when representing classes based on objects stored in databases (hence the name of the module). That way an object can be created, without triggering a DB lookup. Later if data is accessed and it is not currently present in the object, it can be retrieved on an as-need basis.
attributes() still supports the standard Class::ObjectTemplate syntax of a list of attribute names.
attributes()
To use the new functionality, the new key-value syntax must be used. Any method names specified in the lookup array, will trigger undefined. Those specified in the no_lookup will not trigger undefined().
lookup
no_lookup
A class that inherits from Class::ObjectTemplate::DB must define a method called undefined() in order to utilize the lookup behavior.
Whenever an attribute\'s getter method is invoked, and that attribute\'s value is currently undef, then undefined() will be invoked if that attribute was defined as in the lookup array when attributes() was called.
A class\'s undefined() method can include any specialized code needed to lookup the value for that objects\'s attribute, such as using DBI to connect to a local DB, and retrieve the value from a table.
Class::ObjectTemplate::DB defines a default undefined() which does nothing.
Jason E. Stewart (jason@openinformatics.com)
perl(1).
2 POD Errors
The following errors were encountered while parsing the POD:
'=item' outside of any '=over'
You forgot a '=back' before '=head1'
To install Class::ObjectTemplate::DB, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::ObjectTemplate::DB
CPAN shell
perl -MCPAN -e shell install Class::ObjectTemplate::DB
For more information on module installation, please visit the detailed CPAN module installation guide.