View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Ashish Gulhati > Persistence-Object-Postgres > Persistence::Object::Postgres



Annotate this POD

View/Report Bugs
Module Version: 1.24   Source  


Persistence::Object::Postgres - Object Persistence with PostgreSQL.


  use Persistence::Database::SQL;

  my $db = new Persistence::Database::SQL
    ( Engine => 'Postgres',
      Database => $database_name, 
      Table => $table_name,
      Template => $template_hashref );

  my $object1 = new Persistence::Object::Postgres
    ( __Dope => $db,
      $key => $value );

  my $object2 = new Persistence::Object::Postgres
    ( __Dope => $db, 
      __Oid => $object_id );

  $object1->{$key} = $object2->{$key};

  $object_id = $object1->commit();


This module provides persistence (and optionally, replication) facilities to its objects. Object definitions are stored in a PostgreSQL database as stringified perl data structures, generated with Data::Dumper. Persistence is achieved with a blessed hash container that holds the object data.

Using a template mapping object data to PostgreSQL fields, it is possible to automatically generate PostgreSQL fields out of the object data, which allows you to use poweful PostgreSQL indexing and querying facilities on your database of persistent objects.

This module is intended for use in conjunction with the object database class Persistence::Database::SQL, which provides persistent object database handling functionality for multiple DBMS back-ends. Persistence::Object::Postgres is the module that implements methods for the PostgreSQL back-end.



Creates a new Persistent Object.

  my $object = new Persistence::Object::Postgres 
    ( __Dope => $database );

Takes a hash argument with following possible keys:


The Database of Persistent Entities. This attribute is required and should have as its value a Persistence::Database::SQL object corresponding to the database being used.


An optional Object ID. If this attribute is specified, an attempt is made to load the corresponding persistent object. If no corresponding object exists, this attribute is silently ignored.



Commits the object to the database.


Irrevocably destroys the object. Removes the persistent entry from the DOPE.


If you want to keep a backup of the object before destroying it, use commit() to store it in a different table or database.


Inheriting Persistence::Object::Postgres ^

In most cases you would want to inherit this module to provide persistence for your own classes. If you use your objects to store refs to class data, you'd need to bind and detach these refs at load() and commit(). Otherwise, you'll end up with a separate copy of class data for every object which will eventually break your code. See perlobj(1), perlbot(1), and perltoot(1), on why you should use objects to access class data.



Persistence::Database::SQL(3), Data::Dumper(3), Persistence::Object::Simple(3), DBD::Recall(3), Replication::Recall::DBServer(3), perlobj(1), perlbot(1), perltoot(1).


Persistence::Object::Postgres is Copyright (c) 2000-2001, Ashish Gulhati <>. All Rights Reserved.


Thanks to Barkha for inspiration, laughs and great times, and to Vipul for Persistence::Object::Simple, the constant use and abuse of which resulted in the writing of this module.


This code is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


This is free software. If it breaks, you own both parts.

syntax highlighting: