in reply to How can I catch a failure of use?

You can use the core module Module::Load::Conditional in conjunction with the if pragma:

#! perl use strict; use warnings; use Module::Load::Conditional qw( check_install ); my $something = "This is really something!\n"; my $superduper; BEGIN { $superduper = check_install(module => 'SuperDuperPrinter'); } if ($superduper) { use if $superduper, SuperDuperPrinter => qw( Print ); SuperDuperPrinter::Print($something); } else { print $something; }

Update: The documentation is unclear (to me, anyway), and I didn’t test properly. On further investigation, it appears that the if pragma’s condition is evaluated (silently!) at compile time, not at run time as I assumed. So I have changed:

my $superduper = check_install(module => 'SuperDuperPrinter');

to:

my $superduper; BEGIN { $superduper = check_install(module => 'SuperDuperPrinter'); }

which allows the subsequent use if construct to work correctly.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,