依瑪貓 > DbFramework-1.12 > DbFramework::Persistent

Download:
DbFramework-1.12.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  1
View/Report Bugs
Module Version: 1.10   Source  

NAME ^

DbFramework::Persistent - Persistent Perl object base class

SYNOPSIS ^

  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 ^

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 ^

DbFramework::Util

CLASS METHODS ^

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 ^

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 ^

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

AUTHOR ^

Paul Sharpe <paul@miraclefish.com>

COPYRIGHT ^

Copyright (c) 1997,1998,1999 Paul Sharpe. England. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: