in reply to error handling by pm initialization
Usually the check condition if a module is present is done in BEGIN block using eval to test a require instead of use because the latter is done at compiletime.
Something like the following can be used:
my $gzip; BEGIN{ $gzip = eval { require IO::Compress::Gzip; IO::Compress::Gzip->import(); 1; #UPDATE as per Eily's comment: this +is needed }; print "IO::Compress::Gzip found!" if $gzip; }
Notice also that on CPAN there is Module::Load::Conditional that can be usefull... but must be installed!
Also interesting is perlancar article
L*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: error handling by pm initialization
by homeveg (Acolyte) on Dec 13, 2016 at 13:35 UTC |