NAME
autorequire - Generate module code on demand
SYNOPSIS
use autorequire sub {
my ($this, $f) = @_ ;
if ($f eq 'Useless.pm'){
return "package Useless ;\n1 ;"
}
return undef ;
} ;
DESCRIPTION
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.
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).
CONSTRUCTOR
- new ( HANDLER )
-
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.
METHODS
- $ar->insert( POS )
-
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. - $ar->delete ()
-
Convenience method that removes every occurence of $ar from the @INC array.
- $ar->disable ()
-
Disables $ar, effectively causing it to be skipped over when the INC array is processed.
- $ar->enabled ()
-
Enabled $ar, effectively causing it to be considered when the INC array is processed.
- autorequire->is_loaded( FILENAME )
-
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}
- autorequire->is_installed( 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.
SEE ALSO
AUTHOR
Patrick LeBoutillier, <patl@cpan.org>
COPYRIGHT AND LICENSE
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.