DbFramework::Persistent - Persistent Perl object base class


DbFramework documentation  | view source Contained in the DbFramework distribution.

Index


NAME

Top

DbFramework::Persistent - Persistent Perl object base class

SYNOPSIS

Top

  package Foo;
  use base qw(DbFramework::Persistent);

  package main;
  $foo = new Foo($table,$dbh,$catalog);
  $foo->attributes_h(\%foo};
  $foo->insert;
  $foo->attributes_h(\%new_foo);
  $foo->update(\%attributes);
  $foo->delete;
  $foo->init_pk;
  @foo     = $foo->select($condition,$order);
  $hashref = $foo->table_qualified_attribute_hashref;
  $code    = DbFramework::Persistent::make_class($name);

DESCRIPTION

Top

Base class for persistent objects which use a DBI database for storage. To create your own persistent object classes subclass DbFramework::Persistent (see the make_class() class method.)

SUPERCLASSES

Top

DbFramework::Util

CLASS METHODS

Top

new($table,$dbh,$catalog)

Create a new persistent object. $table is a DbFramework::Table object or the name of a database table. $dbh is a DBI database handle which refers to a database containing a table associated with $table. $catalog is a DbFramework::Catalog object.

make_class($name)

Returns some Perl code which can be used with eval() to create a new persistent object (sub)class called $name.

OBJECT METHODS

Top

Attributes in a persistent object which relate to columns in the associated table are made available through the attribute ATTRIBUTES_H. See AUTOLOAD() in DbFramework::Util for the accessor methods for this attribute.

delete()

Delete this object from the associated table based on the values of it's primary key attributes. Returns the number of rows deleted if supplied by the DBI driver.

insert()

Insert this object in the associated table. Returns the primary key of the inserted row if it is a Mysql 'AUTO_INCREMENT' column or -1.

update(\%attributes)

Update this object in the associated table. %attributes is a hash whose keys contain primary key column names and whose values will be concatenated with 'ANDs' to form a SQL 'WHERE' clause. The default values of %attributes is the hash returned by attributes_h(). Pass the current primary key attributes as an argument in %attributes when you need to update one or more primary key columns. Returns the number of rows updated if supplied by the DBI driver.

select($conditions,$order)

Returns a list of objects of the same class as the object which invokes it. Each object in the list has its attributes initialised from the values returned by selecting all columns from the associated table matching $conditions ordered by the list of columns in $order.

as_html_form()

Returns an HTML form representing the object, filled with the object's attribute values.

init_pk()

Initialise an object by setting its attributes based on the current value of the its primary key attributes.

table_qualified_attribute_hashref()

Returns a reference to a hash whose keys are the keys of %ATTRIBUTES_H with a prefix of $table, where $table is the table associated with the object and whose values are values from %ATTRIBUTES_H. This is useful for filling a template (see fill() in DbFramework::Template.)

SEE ALSO

Top

DbFramework::Util, DbFramework::Table and DbFramework::Template.

AUTHOR

Top

Paul Sharpe <paul@miraclefish.com>

COPYRIGHT

Top


DbFramework documentation  | view source Contained in the DbFramework distribution.