The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 223:

'=item' outside of any '=over'

Around line 225:

You forgot a '=back' before '=head1'