NAME
maybe - Use a Perl module and ignore error if can't be loaded
SYNOPSIS
use Getopt::Long;
use maybe 'Getopt::Long::Descriptive';
if (Getopt::Long::Descriptive->VERSION) { # run-time checking
Getopt::Long::Descriptive::describe_options("usage: %c %o", @options);
}
else {
Getopt::Long::GetOptions(\%options, @$opt_spec);
}
use maybe 'Carp' => 'confess';
use constant HAS_CARP => !! Carp->VERSION;
if (HAS_CARP) { # compilation-time checking
confess("Bum!");
}
else {
die("Bum!);
}
DESCRIPTION
This pragma loads a Perl module. If the module can't be loaded, the error will be ignored. Otherwise, the module's import method is called with unchanged caller stack.
USAGE
- use maybe Module;
-
It is exactly equivalent to
BEGIN { eval { require Module; }; Module->import; }
except that Module must be a quoted string.
- use maybe Module => LIST;
-
It is exactly equivalent to
BEGIN { eval { require Module; }; Module->import( LIST ); }
- use maybe Module => version, LIST;
-
It is exactly equivalent to
BEGIN { eval { require Module; Module->VERSION(version); } Module->import( LIST ); }
- use maybe Module => '';
-
If the LIST contains only one empty string, it is exactly equivalent to
BEGIN { eval { require Module; }; }
SEE ALSO
BUGS
If you find the bug, please report it.
AUTHOR
Piotr Roszatycki <dexter@debian.org>
COPYRIGHT
Copyright (C) 2008 by Piotr Roszatycki <dexter@debian.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.