http://www.perlmonks.org?node_id=886541

vkon has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Everyone knows that perl IO could be "intercepted" using PerlIO layer, i.e. one could create file handle that is mapped into memory (or anywhere else)

Is it possible for directories?

Something like Tie::TextDir - but other way round - Tie::TextDir maps directory to tied perl hash, but I want the opposite - any read of said directory should consult my hash (or just call my callback).

To say, tcl/tk have this mechanics.
I wonder - does perl have this possibility?

TIA,
vkon

  • Comment on could be directory "virtualized" from perl, like PerlIO but for directories?

Replies are listed 'Best First'.
Re: could be directory "virtualized" from perl, like PerlIO but for directories?
by snoopy (Curate) on Feb 07, 2011 at 05:00 UTC
    On the heavy side, Fuse::Simple lets you map a file system to Perl hashes.

    FUSE is implemented at the OS level rather than being Perl specific. it doesn't require root access, but does need a server process (or at least a thread).

    The files are really mounted and are visible to Perl and other processes. It's a deeper abstraction which may or may not be what you want.

    As a final catch, the underlaying Fuse module claims to only work well under Linux or BSD. FUSE however is widely available on other platforms, including Windows.

    I just thought it might be of interest. See also the wikipedia entry Filesystem in Userspace.

Re: could be directory "virtualized" from perl, like PerlIO but for directories?
by ikegami (Patriarch) on Feb 07, 2011 at 03:19 UTC
    Globally overriding opendir and readdir might do what you are trying to do. It won't affect XS modules, though.
Re: could be directory "virtualized" from perl, like PerlIO but for directories?
by Anonymous Monk on Feb 07, 2011 at 00:14 UTC