Sergey Rusakov > ePortal-4.5 > ePortal::ThePersistent::Base

Download:
ePortal-4.5.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 4.5   Source  

NAME ^

ePortal::ThePersistent::Base - Base class for storage objects

SYNOPSYS ^

This package is used for handy work with database objects: SELECT, UPDATE, INSERT, DELETE.

METHODS ^

new()

Object constructor. Parameters:

Returns new blessed and initialized object.

initialize()

Object initialization block, called from new() constructor. initialize() is used for attributes initialization. It is the place to override in inherited modules to add its own attributes.

initialize() calls datastore() with all passed parameters.

Parameters are the same as for object constructor. Only Attributes parameter is used internally.

Returns none.

datastore()

It is the place to initialize database related things like DBH connection. Called from new() constructor.

Should not be called directly.

Parameters are the same as for object constructor. See Storage related variables for more details.

Returns newly created database handle.

attribute()

Returns named attribute parameters as hash. In scalar context returns hash ref.

If attribute does not exists then undef is returned. This method is used to check attribute existance.

attributes()

Returns names of ALL attributes of the object as array.

add_attribute()

Add an attribute to the object. Attribute information is used when SQL statement is constructed or when attribute datatype is needed to know.

Returns none.

value()

Get or set the value of attribute.

Returns new or current value of attribute.

clear()

Clears (undefs) the fields of the object. This method calls value() directly. No overloaded value() methods will be triggered.

Returns none.

update()

Updates existing object in the datastore.

Returns True if UPDATE was successful.

save()

Saves the object to the data store (insert or update).

Returns:

1 if the object did previously exist in the datastore

0 if the object did not previously exist

undef on error

restore()

Restores the object from the data store.

Returns True if the object was successfully restored and False if the object is not found.

restore_all()

Restores all the objects from the data store and optionally sorted.

Returns none.

restore_next()

Restores the next object from the data store that matches the query expression in the previous restore_where or restore_all method calls.

Returns True if an object was restored and False if an object was not restored - no more objects to restore

data()

Gets/Sets all data fields of an object.

Returns $href - a reference to a hash of object data

insert()

Inserts new object into datastore. If ID attribute is auto_increment then newly generated number for ID is stored in object via _id().

Returns True if INSERT was successful.

delete()

Delete the object.

Returns True if DELETE was successful.

delete_where()

Conditionaly deletes objects.

Note: Obligatory WHERE clause will be added

Returns True if DELETE was successful. May be return a number of deleted rows?

restore_where()

Execute conditional SELECT statement.

add_where()

Helper function. Adds another WHERE condition possible ANDed with existing one.

Returns none.

where()

Get/Set obligatory WHERE clause for the object.

Returns ñurrent where clause

validate()

Validates internal data before insert of update. This method does nothing and is subject to override in inherited modules.

Returns undef on success or human readable error message if the object is not valid.

PRIVATE METHODS ^

_check_dbi_error()

Checks for errors in DBI and croaks if an error has occurred.

dbh()

Returns the handle of the database.

_id()

Gets/Sets the ID of the object. ID may be an array.

check_id()

Checks that the ID of the object is valid. That is every ID attribute is defined.

SUPPORTED DATA TYPES ^

VarChar

Number

DateTime

Date

YesNo

INTERNAL VARIABLES ^

Storage related variables

Attributes

Other variables

ATTRIBUTE PARAMETERS ^

A lot of attribute parameters are used for description, detalization and visualization.

syntax highlighting: