Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
DB(3)		      User Contributed Perl Documentation		 DB(3)

NAME
       Class::ObjectTemplate:DB	- Perl extension for an	optimized template
       builder base class with lookup capability.

SYNOPSIS
	 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);
	 }

DESCRIPTION
       Class::ObjectTemplate::DB extends Class::ObjectTemplate in one simple
       way: the	"undefined()" method.

       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".

       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.

   METHODS
       attributes('attr1', 'attr2')
       attributes(lookup => ['attr1'], no_lookup => ['attr2'])
	   "attributes()" still	supports the standard Class::ObjectTemplate
	   syntax of a list of attribute names.

	   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()".

       undefined($self,	$attr_name)
	   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.

   EXPORT
       attributes()

AUTHOR
       Jason E.	Stewart	(jason@openinformatics.com)

SEE ALSO
       perl(1).

POD ERRORS
       Hey! The	above document had some	coding errors, which are explained
       below:

       Around line 223:
	   '=item' outside of any '=over'

       Around line 225:
	   You forgot a	'=back'	before '=head1'

perl v5.32.1			  2002-02-25				 DB(3)

NAME | SYNOPSIS | DESCRIPTION | AUTHOR | SEE ALSO | POD ERRORS

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=Class::ObjectTemplate::DB&sektion=3&manpath=FreeBSD+13.0-RELEASE+and+Ports>

home | help