The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Filesys::Virtual::Base - A base class for virtual filesystems

SYNOPSIS

  package My::Virtual::FS;
  use base 'Filesys::Virtual::Base';

  my $fs = Filesys::Virtual::Plain->new();

  print foreach ($fs->list('/'));

DESCRIPTION

This module is used by other modules to provide a virtual filesystem.

CONSTRUCTOR

new()

You can pass the initial cwd, root_path, and home_path as a hash.

REQUIRED SUB-CLASS METHODS

stat
test($test, $path)

Perform a perl type test on a file and returns the results.

For example to perform a -d on a directory.

  $self->test('d','/testdir');

See filetests in perlfunc (commandline: perldoc perlfunc)

# -r File is readable by effective uid/gid. # -w File is writable by effective uid/gid. # -x File is executable by effective uid/gid. # -o File is owned by effective uid.

# -R File is readable by real uid/gid. # -W File is writable by real uid/gid. # -X File is executable by real uid/gid. # -O File is owned by real uid.

# -e File exists. # -z File has zero size. # -s File has nonzero size (returns size).

# -f File is a plain file. # -d File is a directory. # -l File is a symbolic link. # -p File is a named pipe (FIFO), or Filehandle is a pipe. # -S File is a socket. # -b File is a block special file. # -c File is a character special file. # -t Filehandle is opened to a tty.

# -u File has setuid bit set. # -g File has setgid bit set. # -k File has sticky bit set.

# -T File is a text file. # -B File is a binary file (opposite of -T).

# -M Age of file in days when script started. # -A Same for access time. # -C Same for inode change time.

mkdir($path, $mode);

Should create a directory with $mode (defaults to 0755) and chown()'s the directory with the uid and gid. The return value is from mkdir().

unlink($path)

Should delete a file

rmdir($path)

Should delete the file or directory at $path if possible

list($path)

List the files under $path

open_read($path)

Returns a file handle which contains the data associated with $path

close_read($fh)

Closes a file handle that was opened with open_read.

open_write($path)
close_write($fh) Perform a perl type test on a file and returns the results.
chmod($mode, $path)

Modifies the permissions of the filesystem. Returns blank by default.

METHODS

cwd

Gets or sets the current directory, assumes / if blank. This is used in conjunction with the root_path for file operations. No actual change directory takes place.

root_path($path)

Get or set the root path. All file paths are off this and cwd For example:

  $self->root_path('/home/ftp');
  $self->cwd('/test');
  $self->size('testfile.txt');

The size command would get the size for file /home/ftp/test/testfile.txt not /test/testfile.txt

modtime($file)

Gets the modification time of a file in YYYYMMDDHHMMSS format.

size($file)

Gets the size of a file in bytes.

delete($file)

Deletes a file, returns 1 or 0 on success or failure.

chdir($dir)

Changes the cwd to a new path from root_path. Returns undef on failure or the new path on success.

list_details($dir)

Returns an array of the files in ls format.

test($test,$file)

close_read($fh)

Performs a $fh->close()

close_write($fh)

Performs a $fh->close()

seek($fh, $pos, $wence)

Performs a $fh->seek($pos, $wence). See IO::Seekable.

utime($atime, $mtime, @files)

Performs a utime() on the file(s). It changes the access time and mod time of those files.

TODO

Lots. This really shouldn't be used yet until coverage is strengthened. Next up, we should provide higher level abstractions for certain kinds of file operations, such as copy and move. Additionally, there seems to be a bit of boiler plate required at the beginning of each method implementation, so abstracting the calls a bit more should be done in the near future.

AUTHOR

Norman Nunley <nnunley@cpan.org>, based on the work of David Davis, <xantus@cpan.org>, http://teknikill.net/

SEE ALSO

perl(1), Filesys::Virtual, Filesys::Virtual::Plain, POE::Component::Server::FTP, Net::DAV::Server, HTTP::Daemon, http://perladvent.org/2004/20th/