Movatterモバイル変換


[0]ホーム

URL:


 / 
maybe-0.0202
River stage zero No dependents
/maybe

NAME

maybe - Use a Perl module and ignore error if can't be loaded

SYNOPSIS

use Getopt::Long;use maybe 'Getopt::Long::Descriptive';if (maybe::HAVE_GETOPT_LONG_DESCRIPTIVE) {  Getopt::Long::Descriptive::describe_options("usage: %c %o", @options);}else {  Getopt::Long::GetOptions(\%options, @$opt_spec);}use maybe 'Carp' => 'confess';if (maybe::HAVE_CARP) {  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.

The special constantmaybe::HAVE_MODULE is created and it can be used to enable or disable block of code at compile time.

USAGE

use maybeModule;

It is exactly equivalent to

BEGIN { eval { require Module; }; Module->import; }

except thatModule must be a quoted string.

use maybeModule =>LIST;

It is exactly equivalent to

BEGIN { eval { require Module; }; Module->import( LIST ); }
use maybeModule =>version,LIST;

It is exactly equivalent to

BEGIN { eval { require Module; Module->VERSION(version); } Module->import( LIST ); }
use maybeModule => '';

If theLIST contains only one empty string, it is exactly equivalent to

BEGIN { eval { require Module; }; }

CONSTANTS

HAVE_MODULE

This constant is set after trying to load the module. The name of constant is created from uppercased module name. The "::" string and any non-alphanumeric character is replaced with underscore. The constant contains the true value if the module was loaded or false value otherwise.

use maybe 'File::Spec::Win32';return unless maybe::HAVE_FILE_SPEC_WIN32;

As any constant value it can be used to enable or disable the block code at compile time.

if (maybe::HAVE_FILE_SPEC_WIN32) {    # This block is compiled only if File::Spec::Win32 was loaded    do_something;}

SEE ALSO

if,all,first.

BUGS

The Perl doesn't clean up the module if it wasn't loaded to the end, i.e. because of syntax error.

The name of constant could be the same for different modules, i.e. "Module", "module" and "MODULE" generate maybe::HAVE_MODULE constant.

If you find the bug or want to implement new features, please report it athttp://rt.cpan.org/NoAuth/Bugs.html?Dist=maybe

AUTHOR

Piotr Roszatycki <dexter@cpan.org>

COPYRIGHT

Copyright (C) 2008, 2009 by Piotr Roszatycki <dexter@cpan.org>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Seehttp://www.perl.com/perl/misc/Artistic.html

Module Install Instructions

To install maybe, copy and paste the appropriate command in to your terminal.

cpanm

cpanm maybe

CPAN shell

perl -MCPAN -e shellinstall maybe

For more information on module installation, please visitthe detailed CPAN module installation guide.

Keyboard Shortcuts

Global
sFocus search bar
?Bring up this help dialog
GitHub
gpGo to pull requests
gigo to github issues (only if github is preferred repository)
POD
gaGo to author
gcGo to changes
giGo to issues
gdGo to dist
grGo to repository/SCM
gsGo to source
gbGo to file browse
Search terms
module: (e.g.module:Plugin)
distribution: (e.g.distribution:Dancer auth)
author: (e.g.author:SONGMU Redis)
version: (e.g.version:1.00)

[8]ページ先頭

©2009-2025 Movatter.jp