http://qs321.pair.com?node_id=28806


in reply to Runtime loading of arbitrary objects

-or- I've got a sytem that uses a Session module to define and control all the business rules of any given application. It uses a object factory method:
########################################### # object factory method # $class is the class of the method to be created sub new_object { my $self = shift; my $class = shift; my $id = shift; my $dbh = $self->{'dbh'}; my $object = { 'id' => $id, 'dbh' => $dbh, }; bless $object, $class; $object->init; return $object; }

$class is the object class, $id is an optional object id (for instatiating a particular object from a database for example). The method then calls $class->init which is an initialization method which handles all the details of the given class. Essentially it's just a generic constructor. Technically your classes don't need one if they are going to be called by the base module.

You have to use all the modules you plan to invoke this way in the base "Session" module, but you already know all the modules you're going to use, right?

-Matthew