in reply to How can I catch a failure of use?
What you're looking for may be something like
my $module_loaded; BEGIN { eval { require Foo; Foo->import(); $module_loaded = 'Foo'; 1; } or eval { require Bar; Bar->import(); $module_loaded = 'Bar'; 1; } or do { # Whatever you do when you can not load # any of the modules you want. }; }
The BEGIN block is run the instant its close bracket is compiled, and anything imported by the import() is available to subsequent compilaiton. Any arguments you would pass to 'use' (except version) get passed to import(). If you wish to specify a minimum version, do
Module->VERSION( 3.14 );after you require() the module. If you read the docs for 'use' you will find it explained in more or less the same terms I have given here.
|
|---|