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


in reply to Runtime loading of arbitrary objects

If I understand you correctly, this does what you want.

use strict; my $type = shift || 'CGI'; require "$type.pm"; my $obj = $type->new; print ref $type;

The trick is to use require instead of use, as require is executed at runtime (when you will know which object you want) as opposed to use which is executed at compile time (when you won't know what you want).

This will work as long as you're using pure OO modules which don't export anything that you need. If you need to use exported data then you'll have to add a call to:

$type->import;

After the call to require.

--
<http://www.dave.org.uk>

European Perl Conference - Sept 22/24 2000, ICA, London
<http://www.yapc.org/Europe/>