File::Redirect - override native perl file oprations
$ unzip -l Foo-Bar-0.01.zip Archive: Foo-Bar-0.01.zip Length Date Time Name -------- ---- ---- ---- 0 02-25-12 07:46 Foo-Bar-0.01/ 0 02-25-12 07:47 Foo-Bar-0.01/lib/ 0 02-25-12 07:47 Foo-Bar-0.01/lib/Foo/ 43 02-25-12 07:47 Foo-Bar-0.01/lib/Foo/Bar.pm -------- ------- 43 4 files $ unzip -p Foo-Bar-0.01.zip Foo-Bar-0.01/lib/Foo/Bar.pm package Foo::Bar; sub foo { 42 } 1; $ cat test.pl use File::Redirect::lib ('Zip', 'Foo-Bar-0.01.zip', '/Foo-Bar-0.01/lib'); use Foo::Bar; print Foo::Bar::foo(), "\n"; $ perl test.pl 42
Perl's own use and require cannot be overloaded so that underlying file requests are mapped to something else. This module hacks IO layer system so that one can fool Perl's IO into thinking that it operates on files while feeding something else, for example archives.
use
require
The framework currently overrides only stat and open builtins, which is enough for hacking into use and require. The framework though is capable of being extended to override other file- and dir- based operations, but that's probably is easier to do separately by overriding *CORE::GLOBAL:: functions.
stat
open
*CORE::GLOBAL::
Warning: works only if perl's PERL_IMPLICIT_SYS is enabled
Similar to unix mount(1) command, the function 'mounts' an abstract data entity ($request) into file path $as_path by sending it to $provider. For example, provider Simple treats request as path-content hash. After this command
Simple
mount( 'Simple', { 'a' => 'b' }, 'simple:')
reading from file 'simple:a' yield 'b' as its content. See also File::Redirect::Zip.
The function return success flag; on failure, $@ contains the error.
Removes data entity associated with $path.
Dmitry Karasik, <dmitry@karasik.eu.org>.
To install File::Redirect, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::Redirect
CPAN shell
perl -MCPAN -e shell install File::Redirect
For more information on module installation, please visit the detailed CPAN module installation guide.