UNIVERSAL::require - require modules from a variable



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;"
  Some::Module->require;
  # Ditto
  my $module = 'Some::Module';
  $module->require;


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. So instead of doing some arcane eval() work, you can do this:

    $module->require;

And use Some::Module can be done dynamically like so:

    BEGIN {
        $module->require;
        $module->import;
    }

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 $return_val = $module->require;
  my $return_val = $module->require($version);

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 any 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 not die. The error will be in $UNIVERSAL::require::ERROR.


AUTHOR

Michael G Schwern <schwern@pobox.com>


SEE ALSO

the UNIVERSAL::exports manpage, require in the perlfunc manpage, http://dev.perl.org/rfc/253.pod

 UNIVERSAL::require - require modules from a variable