I have several Nagios plugins that were using Nagios::Plugin
. The module is now deprecated and was substituted by Monitoring::Plugin
.
As several distributions are not updated yet I check in the code which module is available
sub load_module {
my @names = @_;
my $loaded_module;
for my $name (@names) {
my $file = $name;
# requires need either a bare word or a file name
$file =~ s{::}{/}gsxm;
$file .= '.pm';
eval {
require $file;
$name->import();
};
if ( !$EVAL_ERROR ) {
$loaded_module = $name;
last;
}
}
if ( !$loaded_module ) {
# handle error ...
exit 2;
}
return $loaded_module;
}
my $plugin_module = load_module( 'Monitoring::Plugin', 'Nagios::Plugin' );
my $plugin_threshold_module = load_module( 'Monitoring::Plugin::Threshold', 'Nagios::Plugin::Threshold' );
I used to check for the module availability in a Makefile.PL
file with
requires 'Nagios::Plugin' => 0;
requires 'Nagios::Plugin::Threshold' => 0;
and the use the module in my plugin.
Is there a standard way in Makefile.PL to check for a module (i.e., Monitoring::Plugins
) and if not available check if another option is available (i.e., Nagios::Plugin::
)?