On 3/8/06 10:24 PM, "John Siracusa" <[EMAIL PROTECTED]> wrote:

> On 3/8/06 10:11 PM, Nilson Santos Figueiredo Junior wrote:
>> It's usually simple glue code and without it, things get less coherent.
>> You get one nice thing, though: $c->model('Artist') (where $c is the
>> Catalyst context object) returns the appropriate object for the
>> "Artist" model.
> 
> What's the appropriate object?  Should that return a class name or a row
> object or what?
> 
>> I think the main thing really is the Helper class provided along with
>> the models, which provide scaffolding so you're up and running as
>> quickly as possible using that model.
> 
> Do many people use the helpers and scaffolding?  I always imagined that
> people might use those to play with, but then write stuff form scratch when
> creating their first real app.
> 
>> I think you'd probably be the best one to do this, since you'd know
>> exactly how RDBO should be used.
> 
> Well, anyone could read the Rose::DB and RDBO tutorials and have all the
> information they need, I think.
> 
>> Either way, I think that if you don't do it, sooner or later someone else
>> will.
> 
> I'll gladly help anyone who wants to try, but I have many other things on my
> list right now.  Although if someone could provide some example code showing
> how Catalyst::Model::RDBO would be used in a real Catalyst app, it'd
> probably take me only a few hours to whip up the actual code to do it.  The
> hang-up is, and has always been, exactly what Catalyst::Model::RDBO should
> do, not how to do it.

I put some code together just for playing.  I chose to go the route that I
think John would like:  autogenerate a set of modules and then hand-edit for
"tuning" and adding behavior (as opposed to the DBIx::Class route of
autogenerating all the classes at runtime, but that should be pretty
straightforward using RDBO, also).  Here is the simple "helper" script for
generating the package code for each table (and a manager package for
each)--very simple!  (Thanks, John!)  Oh, and the standard disclaimer--I did
this a few months back and do not guarantee that the code is perfect (or
even without bugs at this point).

# make.rose.modules.pl
#!/usr/bin/perl
use strict;
use warnings;

use Rose::DB::Object::Loader;
# use appropriate DB and base classes
use ApacheAdmin::Model::DB;
use ApacheAdmin::Model::Base;


my $loader = 
    Rose::DB::Object::Loader->new(
        db           => ApacheAdmin::Model::DB->new,
        class_prefix => 'ApacheAdmin::Model',
        base_classes => 'ApacheAdmin::Model::Base'
    );

$loader->make_modules(
    #assumes this file is in project/scripts directory and that
    #there is a project/lib folder
    module_dir   => '../lib'
);


The ApacheAdmin::Model::DB class is just a simple Rose::DB subclass, but in
the Catalyst app namespace.  It suffices to simply use your DB class in the
ApacheAdmin::Model::DB module.

And now for the ApacheAdmin::Model::Base class.  Note there is nothing
special about the base class except for "use Catalyst::Model".

package ApacheAdmin::Model::Base;
use strict;

use ApacheAdmin::Model::DB;

use Rose::DB::Object;
our @ISA = qw(Rose::DB::Object);
use Catalyst::Model;

sub init_db { my $db = ApacheAdmin::Model::DB->new();
              $db->connect_option(AutoCommit => 0);
              $db->connect_option(RaiseError => 1);
              return $db; }

1;

And in a ApacheAdmin::Controller::User module, a SIMPLE example use:

sub list : Local  {
    my ( $self, $c ) = @_;

    # Hello World
    my 
$users=$c->model("User::Manager")->get_users(with_objects=>['groups']);
    $c->stash->{users} = $users;
    $c->stash->{template} = 'list.tt';
}

Note that the RDBO::Model classes do not have any magical behavior besides
being autoregistered into the app so that you can call
$c->model("RDBO::Model::Class")->method.

I could see a number of ways to go for automatically producing such code,
but I would leave that to others to play with.  Just wanted to give an
example of what I have tried in just playing.  I do not have any
"production" code doing this yet, but that is mainly because I haven't had
to produce any lately.  If I do, I will probably do something along these
lines.

Sean





-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to