On 11/28/05 1:21 PM, "John Siracusa" <[EMAIL PROTECTED]> wrote:

> On 11/28/05, Sean Davis <[EMAIL PROTECTED]> wrote:
>> Is there a way to pass the make_classes params via RDBO::Loader->new?
>> Instead of doing:
>> 
>> My $loader = RDBO::Loader->new()
>> 
>> Then
>> 
>> $loader->make_classes(include_tables => 'xyz')
>> 
>> Doing something like:
>> 
>> My $loader = RDBO::Loader->new(make_classes => {exclude_tables => 'xyz'});
>> 
>> $loader->make_classes();
> 
> Nope.  I debated how many params to make object attrs and how any to
> leave as args to make_classes.  In the end, I decided that the
> include/exclude stuff should be args to make_classes.  The usage
> scenario I imagined is setting up a loader once and then running it a
> few times with different include/exclude args to make classes with and
> without managers, for example, for different sets of tables.
> 
> Is there a reason you want to set up the include/exclude stuff in the
> loader itself instead of passing args to make_classes?
> 
>> Another unrelated question--how does one get a list of the "loaded" tables
>> from the loader after the creation is completed?  Does something like
>> $loader->classes exists?
> 
> No, since the classes created are not object data.  They're just the
> result of a particular call to make_classes().  If you want to see the
> list of tables, catch the classes returned by make_classes() and then
> call $class->meta->table on each Rose::DB::Object-derived class made.

Ok.  To be a bit more transparent, I have been working on a
Catalyst::Model::RDBO (for my own use, anyway).  I am simply modeling it on
C::M::CDBI.  It works fine, except that the arguments to RDBO::Loader come
in two pieces, those for the loader object and those for the make_classes
call.  Because of the NEXT usage, there will need to be some parameter
shifting in order for my current RDBO::Loader strategy to work as cleanly as
the CDBI model.  Below is a cut of the code.  Note how in this scenario
(because I haven't figured out how to do it nicely), I have hard-coded the
exclude_tables argument.  Obviously, this is where I would like to change
things.  As for the $loader->classes, it would be nice to have access to the
loaded classes after the fact; it makes sense to have this information
stored somewhere, but I agree that it isn't really object-data, exactly.


package Catalyst::Model::RDBO;

use strict;
use base qw/Catalyst::Base Rose::DB::Object/;
use NEXT;
use Rose::DB::Object::Loader;

our $VERSION = '0.11';

__PACKAGE__->mk_accessors('loader');


sub new {
    my $class = shift;
    my $self  = $class->NEXT::new( @_ );
    my $c     = shift;
    $self->{class_prefix}               ||= ref $self;
    my @classes;
    eval { $self->loader( Rose::DB::Object::Loader->new(%$self) ) };
    if ($@) { 
        Catalyst::Exception->throw( message => $@ );
    }
    else {
        @classes = $self->loader->make_classes(exclude_tables=>'go');
        $c->log->debug(
               'Loaded classes' . join(" ",@classes))
          if $c->debug;
    }
    for my $class ( @classes ) {
        $c->components->{$class} ||= bless {%$self}, $class;
        no strict 'refs';
        *{"$class\::new"} = sub { bless {%$self}, $class };
    }
    return $self;
}

1;

And to use:

package stuff1::Model::RDBO;
use strict;

use base 'Catalyst::Model::RDBO';

__PACKAGE__->config(
   db_dsn       => 'dbi:Pg:dbname=annodb4;host=localhost',
   db_username  => 'xxx',
   db_password  => '',
   db_options   => {AutoCommit => 1});

1;




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to