Try::Tiny is a good, if flaky option. It has several obscure failure modes.
You might want to look at some of the newer keyword based modules. I
haven't tried them yet, so I don't have a strong opinion.
On Fri, Nov 17, 2017, 13:45 Simon Reinhardt wrote:
> Thanks for your answer.
> Maybe I should
Thanks for your answer.
Maybe I should use Try::Tiny:
#!/usr/bin/env perl
use 5.020;
use warnings;
use strict;
use Try::Tiny;
use Module::Load;
my $module= 'AB::CD';
try {
autoload($module);
}
catch {
if ($_ =~ /Compilation failed in require/) {
say "compilation failed";
}
This is probably the best technique to use. I would note that your code is
not handling exceptions in the safest way.
You can increase the safety of your code by saying:
eval {
autoload($module);
1; #force true value on success
} or do {
if ($@ =~ /Compilation failed in require/) {