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. Most of these sub-classes are fundamentally the same, like this one. package BusObj::BusObj; use 5.006001; use strict; use warnings; use base "DataStore"; our $VERSION = '0.01'; __PACKAGE__->table( "busobj" ); __PACKAGE__->columns( All => qw/ busobjid active name class / ); 1; Is there any way that I can create these packages (a.k.a. classes) at runtime ? 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 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 alternative is just to make real sub-classes for all the business objects but it seems that there should be a better (and more easily testable) way to do it. Anyone got any ideas ? Simon. --
