Monday, February 16, 2009

A roadmap for my Perl ORM

Mostly for my own purposes (and subject to modification).

0.1 Handle serializing a simple OIO class
0.2 Handle de-serializing a simple OIO class
0.3 Allow embedding classes (1-1 relationship) in a class (serialize/deserialize)
1.0 Allow 1-many, many-1, many-many relationships between classes (to separate tables, using join table if necessary)

Tuesday, February 10, 2009

Thoughts on ORM in Perl

One thing that I really admire from Java world is the EJB3 Persistence annotations. A class can be made persistent with a simple mark-up:

@Entity
class Foo {
private int count;
private String name;
@Transient
private int temp_var;
....
}

The @Entity notation indicates that the class should map to a table (unless overridden, it will use the class name as the table name). Every field then automatically maps to a column in the table (column names can be overridden) unless marked with the @Transient annotation.

I was thinking that something similar could be executed in Perl using perl attributes. I could do something like

package Foo;
use Object::InsideOut;

my @int :Field :Entity;
my @string :Field :Entity;
my @temp_var :Field;
...

Using something like Object::InsideOut seems essential for this sort of attribute-based mark-up, although perhaps I should look at Moose instead (although that does seem to have some significant performance penalties). There are some questions about how to handle exporting the serialization routines. Should I work towards a DAO solution or set up serialization routines directly in the class (perhaps as protected by default with the class making a decision about whether to provide public methods to expose these to clients.

Tuesday, February 3, 2009

A tutorial on attributes

The perldoc on attributes is a bit opaque, so digging about for information on how to program attributes in Perl, I managed to come across slides from a talk at london.pm Using Attributes Effectively (PDF). It suffers a bit in being only the slides and not the talk, but it does cover some things (like the handler functions) that seem to be largely undocumented elsewhere.