On Sat, 18 Jan 2003, Simon Wilcox wrote:
> I'm not sure which piece of magic might do want I want but here's the
> problem:
>
> I'm buiding an app using Class::DBI. There is a master object called
> DataStore which is the sub-class of Class::DBI and from which all the
> business objects (represented by tables in the database) inherit.
>
> Is there any way that I can create these packages (a.k.a. classes) at
> runtime ?
If you have a decent abstract representation of the data you can use eval
to build anything you like. There is a Class::DBI::mysql which can pull
the info out of the database and magic up the class data, if that helps at
all.
> I'm already using a factory class to abstract the implementation away from
> the main logic code. It delays the loading of the sub-classes until
> they're needed to avoid needless compilation (there may be 20 odd business
Sorry, rather tough shit. Class::DBI requires every class with which you
have a relation on sight, ignores errors in require (and makes them
inaccessible and indetectable to the user by performing further requires
to overwrite UNIVERSAL::require::ERROR while leaving the failed modules in
%INC), selects several copies of all your data and proceeds to make them
inconsistent. I'm coming to the conclusion that Class::DBI is fine as long
as you don't have any relations. This makes life boring.
> objects but usually the code will only be acting on two or three) so
> something like
>
> Factory->fetch( 'person', id => 1 )
>
> will first try to 'require' the class that it looks up in a reference
> table.
>
> The goals are (a) to avoid writing repetitive classes; and (b) enable
> expansion of the system by simply adding a new table and an entry
> in the business objects table.
The goals are respectable and I agree with them. I think you might find a
better tool for achieving them.
S.
--
Shevek
I am the Borg.
sub AUTOLOAD{my$i=$AUTOLOAD;my$x=shift;$i=~s/^.*://;print"$x\n";eval
qq{*$AUTOLOAD=sub{my\$x=shift;return unless \$x%$i;&{$x}(\$x);};};}
foreach my $i (3..65535) { &{'2'}($i); }