[Catalyst] CatalystX::CRUD

Peter Karman peter at peknet.com
Fri Sep 21 14:57:35 GMT 2007


I've been thinking the last couple days about ways to expand
Catalyst::Controller::Rose to play more nicely with other models besides
C::M::RDBO. This is per mst's request to open up the RHTMLO goodness to
non-RDBO users, and because I now find myself wanting the same thing. I have a
model that isn't RDBO that I'd like to use in a project.

So I'm proposing the following -- comments/criticism welcome.

* CatalystX::CRUD::Model (CXCM)

A base class for CRUD-like models. CXCM isa Catalyst::Model. Any CXCM subclass
could be used with the C::C::Rose classes (or any other controller that decided
to adhere to the CXCM API). C::M::RDBO would become a CXCM subclass.

CXCM subclasses would need to implement at least the following methods:

 * new_object  - returns CatalystX::CRUD::Object->new()
 * fetch       - returns CatalystX::CRUD::Object->new()->read()
 * search      - returns zero or more CXCO instances as an arrayref
 * interator   - like search() but returns an iterator
 * count       - like search() but returns an integer

(For those following along at home, you'll notice that's basically the
C::M::RDBO API.)

* CatalystX::CRUD::Object (CXCO)

A base class for objects returned by CatalystX::CRUD::Model subclasses. In the
case of RDBO, this would just be a thin wrapper class that 'hasa' RDBO object.
So e.g. calling create() or update() on a CatalystX::CRUD::Object::RDBO object
would just look something like:

 sub create {
    my $self = shift;  # CXCO object
    $self->rdbo->save(@_);
 }

 # same thing for update()

CXCO subclasses would need to implement at least the following methods:

 * create    - write a new object to store
 * read      - load a new object from store
 * update    - save an existing object to store
 * delete    - remove an existing object from store

(How original! CRUD!)

You'll notice that the required CXCO methods are intentionally few. I assume
that subclasses would want to also provide accessors to any underlying objects
so that controllers could act directly on them (e.g., the rdbo() method in the
above create example).

I imagine that there could then be classes like:

 CatalystX::CRUD::Model::DBIC
 CatalystX::CRUD::Object::DBIC
 CatalystX::CRUD::Model::CDBI
 CatalystX::CRUD::Object::CDBI

etc., that would all play nicely with C::C::Rose.

Thoughts?


-- 
Peter Karman  .  peter at peknet.com  .  http://peknet.com/




More information about the Catalyst mailing list