Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Class::HPLOO - Need advice in attributes and object persistence for OODB.

by gmpassos (Priest)
on Feb 08, 2004 at 22:45 UTC ( [id://327511]=perlquestion: print w/replies, xml ) Need Help??

gmpassos has asked for the wisdom of the Perl Monks concerning the following question:

update: Changed the title for who was thinking that this was a release announcement.

I have just released Class::HPLOO 0.11, with support for attributes definitions.

I have inserted the attribute support to build an automatically object persistence system for OODB through Class::HPLOO.

First, some example of the new syntax for attributes:

use Class::HPLOO ; class User { attr( str name , int age , &my_word_type user , &my_word_type pass , + array links ) ; ## my personalized type: sub my_word_type ($value) { $value =~ s/\W//gs ; $value = lc($value) ; return $value ; } ## initializer for the object: sub User ( $name , $age , $user , $pass , @links ) { ## through set method: $this->set_name($name) ; $this->set_links(@links) ; ## through tied key: $this->{age} = $age ; $this->{user} = $user ; $this->{pass} = $pass ; } ## some method: sub dump_user { print "USER: $this->{user}\n" ; print " name: $this->{name}\n" ; print " age: $this->{age}\n" ; print " links: ". join(" ", $this->get_links) ."\n" ; print "\n" ; } } ## USAGE: package main ; my $user = new User( 'Joe' , '30' , 'JOE' , 1234 , 'www.perl.com' , +'www.cpan.org' ) ; $user->dump_user ; exit;

The idea of the attributes, is to give a type to them and the setter and getter methods. Soo, with a method to access or set the attributes we can know when they are changed or not, soo will be possible to define if an object is "dirty" or "clean", needed to make the persistent proxy system.

The DB communication will be made through HDB (a module that I haven't released yet, for now it's just for our internal use in our projects, but will be there for the public). With HDB we don't use SQL, or don't need to use, to work with the DB, we just use commands and syntax based in Perl it self. Soo, we can work with any type of DB without need to care with the nuances of each SQL or behavior of each DB type. Soo, the persistence system will work in any DB, from SQLIte to MySQL and Oracle.

But the seconde idea, is to make an easy and simple way to create a persistence class. For example, in Java the easier framework for persistence is the "Prevayler" system (not made by SUN), where we just declare the clas with that:

public class User implements Serializable { ... }
And bingo, the persistence system is done. But "Prevayler" use a log persistence system, soo it doesn't use DB, just a log with all the commands send to an object. Soo, when the system is reloaded, the objects are rebuild with all the commands in the log.

But for a true persistent system, that works in different processes, different machines and for big systems, it really need to be made with a true DB.

But how to to make this simple and easy in Perl?
I'm talking about the declaration and syntax definition for that. Since how to build what happens behind the framework is just the easy part, specially with the resources that I have here.

For example, in Perl we don't have the "implements" resource for classes. But with just an "extends" system it won't work too, since the persistence system need to change the setter and getter methods, also inserting "mask/layer" classes (proxy) when an object has some association with other object.

But the biggest problem in the definition, is how to just define simple like in the "Prevayler" example, and also define the DB connection?

Soo, before start to work on that, I'm just asking for some opinion from the monks about the persistence system and the new attribute definition.

Thanks in advance,

Graciliano M. P.
"Creativity is the expression of the liberty".

Replies are listed 'Best First'.
Re: Class::HPLOO, attributes and object persistence for OODB.
by Anonymous Monk on Feb 09, 2004 at 05:43 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://327511]
Approved by ybiC
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2024-04-18 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found