The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

HDB::Object - Base class for persistent Class::HPLOO objects.

DESCRIPTION

This is the base class for persistent Class::HPLOO objects.

This will automaticallt make Class::HPLOO classes persistent in any DB handled by HDB.

This persistence framework was built by a group of modules that handle specific parts of the problem:

Class::HPLOO

The class declaration and attribute handler.

HDB::Object

The object persistence and class proxy.

HDB

The DB connection and SQL communication for each DB type.

All of this will create a very automatic way to create persistent objects over a relational DB, what is perfect for fast and easy creation of good systems. For Web Systems this framework is automatically embeded into HPL, where you can count with a lot of resources for fast and powerful creations for the Web.

USAGE

Here's an example of a class built with HDB::Object persistence.

use Class::HPLOO ;

class User extends HDB::Object {

  use HDB::Object ;

  attr( user , pass , name , int age ) ;
  
  sub User( $user , $pass , $name , $age ) {
    $this->{user} = $user ;
    $this->{pass} = $pass ;
    $this->{name} = $name ;
    $this->{age} = time ;
  }

}

You can see that is completly automatic and you don't need to care about the serialization or even about the DB connection, tables and column types.

METHODS

load (CONDITIONS)

Loads an object that exists in the database.

CONDITIONS can be a sequence of WHERE conditions for HDB:

my $users_x = load User('id == 123') ;

my @users = load User('id <= 10' , 'id == 123' , 'name eq "joe"') ;

If CONDITIONS is NOT paste, if wantarray it will return all the objects in the table, or it will return only the 1st:

my $user1 = load User() ;

my @all_users = load User() ;

hdb

Return the HDB object that handles the DB connection.

hdb_dump_table

Dump all the table content, returning that as a string.

hdb_table_exists

Retrun TRUE if the table for the HDB::Object was already created.

hdb_create_table

Create the table for the HDB::Object.

hdb_obj_changed

Return TRUE when the object was changed and need to be updated in the DB.

hdb_max_id

Return the max id in the object table.

hdb_delete

Delete the object from the database.

hdb_save

Save the object in the database.

** Note that you don't need to call this method directly, since when the object is destroied from the memory it will be saved automatically.

DESTROY and AUTO SAVE OBJECT

The object will be automatically saved when the object is destroied.

So if you want to use this automatically save resource you can't overload the sub DESTROY, or at least should call the super method:

class User extends HDB::Object {
  ...
  
  sub DESTROY {
    $this->SUPER::DESTROY ;
    ... # your destroy stuffs.
  }
}

SEE ALSO

HPL, HDB, Class::HPLOO.

AUTHOR

Graciliano M. P. <gm@virtuasites.com.br>

I will appreciate any type of feedback (include your opinions and/or suggestions). ;-P

COPYRIGHT

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