Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

RE: Runtime loading of arbitrary objects

by davorg (Chancellor)
on Aug 21, 2000 at 14:12 UTC ( #28786=note: print w/replies, xml ) Need Help??


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/>

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://28786]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2021-04-11 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?