Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

RE: Runtime loading of arbitrary objects

by davorg (Chancellor)
on Aug 21, 2000 at 14:12 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://28786]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-26 09:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found