Gossamer Forum
Home : General : Perl Programming :

Conditional inline use of use

Quote Reply
Conditional inline use of use
Is it possible to have a 'use' statement as conditional?

For example, rather than calling use Image::Magick; at the top of a .pm file, I want to include
it in the code, so that it is only included when/if the specific code gets executed.
Code:
if ($mode eq 'IM') {

use Image::Magick;

print $IN->header (-type=>'image/png', -cookie => $cookie);
}
else {
print $IN->header (-cookie => $cookie);
}

The problem I have is that when the code above is installed as a plugin for LinksSQL,
it generates an error if Image::Magick is not installed. Even if 'mode' is not 'IM'.

In other words, I have several 'modes' that I would like to use for creating an image.
The admin specifies the 'mode' to use via setup, i.e. IM for Image::Magick, GD for GD::Image, etc...
Then I call the script which should include the necessary module based on 'mode',
and ignore the other modules.

Additionally is there a way to check if a perl module is installed without
interupting the scripts execution?

If so, I could have the admin select a Perl Module to use for image creation
during the installation of the plugin, and install only the code that uses that module.
I would want to give them a dropdown menu of installed choices.

Any pointers/suggestions are appreciated.

Thank you,
Chris
RGB World, Inc. - Software & Web Development.
rgbworld.com
Subject Author Views Date
Thread Conditional inline use of use rgbworld 9449 Sep 4, 2006, 11:52 AM
Post Re: [rgbworld] Conditional inline use of use
fuzzy logic 9245 Sep 4, 2006, 5:51 PM
Thread Re: [rgbworld] Conditional inline use of use
mkp 9259 Sep 7, 2006, 10:10 AM
Post Re: [mkp] Conditional inline use of use
pgwalters 9053 Jan 4, 2007, 1:47 PM