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".


In reply to Class::HPLOO - Need advice in attributes and object persistence for OODB. by gmpassos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.