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
authors about the persistence system and the new attribute definition.

Thanks in advance.

Regards,
Graciliano M. P.


Reply via email to