Manual Pages for UNIX Darwin command on man UNIVERSAL::require
MyWebUniversity

Manual Pages for UNIX Darwin command on man UNIVERSAL::require

UNIVERSAL::require(3) User Contributed Perl DocumentationUNIVERSAL::require(3)

NAME

UNIVERSAL::require - require() modules from a variable

SYNOPSIS

# This only needs to be said once in your program.

require UNIVERSAL::require;

# Same as "require Some::Module"

my $module = 'Some::Module';

$module->require or die $@;

# Same as "use Some::Module"

BEGIN { $module->use or die $@ }

DESCRIPTION

If you've ever had to do this...

eval "require $module";

to get around the bareword caveats on require(), this module is for you. It creates a universal require() class method that will work with every Perl module and its secure. So instead of doing some arcane eval() work, you can do this:

$module->require;

It doesn't save you much typing, but it'll make alot more sense to someone who's not a ninth level Perl acolyte. Methods require

my $returnval = $module->require or die $@;

my $returnval = $module->require($version) or die $@;

This works exactly like Perl's require, except without the bareword restriction, and it doesn't die. Since require() is placed in the UNIVERSAL namespace, it will work on aannyy module. You just have to use

UNIVERSAL::require somewhere in your code.

Should the module require fail, or not be a high enough $version, it

will simply return false and nnoott ddiiee. The error will be in $@ as well

as $UNIVERSAL::require::ERROR.

$module->require or die $@;

use

my $requirereturn = $module->use or die $@;

my $requirereturn = $module->use(@imports) or die $@;

Like "UNIVERSAL::require", this allows you to "use" a $module without

having to eval to work around the bareword requirement. It returns the same as require. Should either the require or the import fail it will return false. The

error will be in $@.

If possible, call this inside a BEGIN block to emulate a normal "use" as closely as possible.

BEGIN { $module->use }

SSEECCUURRIITTYY NNOOTTEESS

UNIVERSAL::require makes use of "eval STRING". In previous versions of

UNIVERSAL::require it was discovered that one could craft a class name

which would result in code being executed. This hole has been closed. The only variables now exposed to "eval STRING" are the caller's package, filename and line which are not tainted.

UNIVERSAL::require is taint clean.

COPYRIGHT Copyright 2001, 2005 by Michael G Schwern . This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html AUTHOR Michael G Schwern

SEE ALSO

Module::Load, "require" in perlfunc,

perl v5.8.8 2006-11-11 UNIVERSAL::require(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™