Dmitry Karasik > File-Redirect-0.04 > File::Redirect



Annotate this POD

View/Report Bugs
Module Version: 0.04   Source  


File::Redirect - override native perl file oprations


   $ unzip -l
     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/
    --------                   -------
          43                   4 files

   $ unzip -p Foo-Bar-0.01/lib/Foo/ 
   package Foo::Bar;
   sub foo { 42 }

   $ cat 
   use File::Redirect::lib ('Zip', '', '/Foo-Bar-0.01/lib');
   use Foo::Bar;
   print Foo::Bar::foo(), "\n";

   $ perl


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.

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.

Warning: works only if perl's PERL_IMPLICIT_SYS is enabled


mount $provider, $request, $as_path

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

   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.

umount $path

Removes data entity associated with $path.


Dmitry Karasik, <>.

syntax highlighting: