Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: (object-oriented programming)

I'm trying to build a wrapper class to hold one of an arbitrary number of "plug-in" modules. My motive here is to load the module, and then pass calls from the outside world to that module, failing gracefully if it can't perform the function. I get the name of the module out of a database query. I can do require $string no problem, but the issue then becomes how do I say $string->new?

Originally posted as a Categorized Question.

  • Comment on Using objects where you don't know the module's name until run time.

Replies are listed 'Best First'.
Re: Using objects where you don't know the module's name until run time.
by tye (Sage) on Nov 07, 2000 at 03:20 UTC
    $string->new()
    Yes, it really is that simple.
Re: Using objects where you don't know the module's name until run time.
by Narveson (Chaplain) on Jan 23, 2008 at 17:03 UTC
    require $class_name;
    only ensures that an exception will be thrown if $class_name hasn't been loaded. Presumably you think all the modules you may ever need will have already been loaded at compile time. If you want require to go out and load the class from a file at runtime, say
    eval "require $class_name";
    This allows you to leave unwanted modules unloaded, with possible performance gains.

    Originally posted as a Categorized Answer.