File::System::Layered - A file system implementation with "layered" roots
use File::System; my $root = File::System->new('Layered', [ 'Real', root => '/usr/local' ], [ 'Real', root => '/usr' ], [ 'Real', root => '/cw/usr/local' ], [ 'Real', root => '/sw/usr/local' ], ); my $dir = $root->lookup('/bin'); print "All files:\n"; print map({ " - $_\n" } $root->children_paths);
This file system allows for the layering of other file systems. A layerd file system contains one or more other file systems such that the list of files available at a certain path in the tree is the union of the files available in all the contained file systems. When reading from or writing to file content, the file system with the highest priority is given preference.
The priority of the file systems is determined during construction, and may be modified later.
The constructor of this module provides the initial layer prioritization. The File::System::Layered package also provides methods for altering the layers after the file system has been established.
File::System::Layered
The constructor establishes the initial layout of the file system. Each element of @file_systems is either a file system object or is a reference to an array that may be passed to File::System::new to construct a file system object.
@file_systems
File::System::new
The layers are prioritized by the order given in @file_systems. The file systems listed first are given the higher priority.
Returns the list of the file system layers in descending order of priority. By using this method to get the list of layers, they can be reordered, removed, added to and then passed back to set_layers to alter the file system.
set_layers
Reset the layers of the file system in descending order of priority. This effectively reinitializes the file system. The semantics are the same as that of the constructor.
This list includes things that aren't always bugs, but eccentricities of the implementation forced by the the nature of the service provided. This provides an explanation for anything that might not be obvious. I've tried to make the implementations work in a simple and natural way, but a few decisions were arbitrary.
The copy, move, and rename methods are stuck within the file system they are in. That is, if you move, rename, or copy a file, the new file, location, or duplicate will be stored within the same layer as the original. If you attempt to move or copy to a location that exists in one layer, but not another, those methods will attempt to use create to create the needed directory in the other layer. Due to these kinds of complications, these methods haven't yet been fully tested.
copy
move
rename
create
Removing a file or directory might not have the expected effect. If there are two layers with the same file or directory, removal will just remove the version in the highest layer, so the file or directory will still appear to exist.
The is_creatable method returns true if any layer returns true. The create method uses the is_creatable of each layer to find out if the file can be created and will create the file on the first layer it finds where it is true.
is_creatable
The glob and find methods rely upon the slowish defaults. This situation could probably be improved with a little bit of effort.
glob
find
File::System, File::System::Object, File::System::Real, File::System::Table
Andrew Sterling Hanenkamp, <hanenkamp@users.sourceforge.net>
Copyright 2005 Andrew Sterling Hanenkamp. All Rights Reserved.
This library is distributed and licensed under the same terms as Perl itself.
To install File::System, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::System
CPAN shell
perl -MCPAN -e shell install File::System
For more information on module installation, please visit the detailed CPAN module installation guide.