autorequire - Generate module code on demand
use autorequire sub { my ($this, $f) = @_ ; if ($f eq 'Useless.pm'){ return "package Useless ;\n1 ;" } return undef ; } ;
autorequire allows you to automatically generate code for modules that are missing from your installation. It does so by placing a handler at the end of the @INC array and forwarding requests for missing modules to the subroutine provided.
autorequire
The subroutine argument can be either a coderef or scalar value, in which case it will be used as a symbolic reference. Note: no error will be generated if the symbolic reference does not resolve. This allows a handler to "kick in" at later time when the subroutine in question is actually defined.
The subroutine must return the code for the module in the form of a filehandle, a scalar reference or a scalar value. A return value of undef will pass control to the next handler (either a previous autorequire handler or Perl's default require mechanism).
Creates a new autorequire object that will call HANDLER when invoked. For it to be of any use you must place the object in the proper array (in this case the @INC array) using the insert method.
Convenience method that places the autorequire object at position POS in the @INC array.
$ar->insert(-1) is equivalent to push @INC, $ar $ar->insert(0) is equivalent to unshift @INC, $ar
Note that it is possible to insert the same autorequire object multiple times in the @INC array by calling $ar->insert() repeatedly.
Convenience method that removes every occurence of $ar from the @INC array.
Disables $ar, effectively causing it to be skipped over when the INC array is processed.
Enabled $ar, effectively causing it to be considered when the INC array is processed.
Convenience method that returns the absolute path of FILENAME if the module FILENAME is found in the %INC hash. Returns undef is the module is not loaded.
autorequire->is_loaded($filename) is equivalent to $INC{$filename}
Convenience method that returns the absolute path of FILENAME if the module FILENAME is installed on the system. It does this by concatenating every entry in @INC with FILENAME and checking if the resulting path exists. Returns undef if the module is not installed.
"require" in perlfunc.
Patrick LeBoutillier, <patl@cpan.org>
Copyright (C) 2005 by Patrick LeBoutillier
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.
To install autorequire, copy and paste the appropriate command in to your terminal.
cpanm
cpanm autorequire
CPAN shell
perl -MCPAN -e shell install autorequire
For more information on module installation, please visit the detailed CPAN module installation guide.