[prev] [thread] [next] [lurker] [Date index for 2004/10/16]
Darren Chamberlain wrote:
> * Bowen Dwelle <bowen at dwelle.org> [2004/10/15 08:19]:
>
>>Simon -- thanks for the pointers. I could certainly hack up Siesta with
>>$prefix -- and I may, in the short run, but doing it via Class::DBI
>>sounds like the right way. Unfortunately, that's _way_ beyond my level
>>of expertise.
>
>
> You might be able to do it like so:
>
> package My::Class::DBI;
>
> use base 'Class::DBI';
> My::Class::DBI->set_db(...);
>
> use constant TABLE_PREFIX => 'my_';
>
> sub table {
> my ($class, $table_name) = @_;
> __PACKAGE__->SUPER::table(TABLE_PREFIX . $table_name);
> }
>
> And then in the subclasses:
>
> package My::Class::DBI::Foo;
>
> use base 'My::Class::DBI';
> My::Class::DBI::Foo->table('foo');
>
> I haven't tested this or anything, of course, just brainstorming.
>
> (darren)
Almost... It turns out that (at least in this case) I don't need to
override Class::DBI::table().
I added this to Siesta::DBI.pm
sub TABLE_PREFIX { return 'siesta_'; }
...hacked init_db to replace a token in the create_database SQL with the
output of the stub above, and then changed the six data object classes
to do
__PACKAGE__->set_up_table( __PACKAGE__->TABLE_PREFIX() . 'list');
instead of
__PACKAGE__->set_up_table('list');
...and that seems to do it!
PS I did the same for Email::Store, adding the prefix sub to
Email::Store::DBI, and the similar things to the data object classes.
The only real ugliness is hacking Class::DBI::DATA::Schema to
my $prefix = Email::Store::DBI->TABLE_PREFIX();
$sql =~ s/TABLE_PREFIX_/$prefix/sg;
which I know isn't right at all, but I don't how to look in the right
place in the calling stack or whatever... It's temporary; I'm sure
someone will be able to advise how to fix this.
-- Bowen
There's stuff above here
Generated at 14:00 on 11 Nov 2004 by mariachi 0.52