MogileFS::Client::FilePaths - Client library for use with FilePaths plugin in MogileFS
use MogileFS::Client::FilePaths; # From MogileFS::Client (See its documentation for details) $mogc = MogileFS::Client->new(domain => "foo.com::my_namespace", hosts => ['10.0.0.2', '10.0.0.3']); $key = "/path/to/file"; # The FilePaths plugin lays a path structure on top of standard mogilefs. $class = "user_images"; # Files still belong to classes $fh = $mogc->new_file($key, $class); print $fh $data; unless ($fh->close) { die "Error writing file: " . $mogc->errcode . ": " . $mogc->errstr; } # Find the URLs that the file was replicated to. May change over time. @urls = $mogc->get_paths($key); # no longer want it? $mogc->delete($key); # List files in a directory @files = $mogc->list("/path/to"); # Each element is a hashref, see below for more keys. @file_names = map { $_->{name} } @files;
This module is a subclass of the MogileFS::Client library, it provides a similar interface for extra functionality provided in the FilePaths plugin.
All methods are inhereted and usable from the MogileFS::Client library, with only the exceptions listed below.
The fourth argument to the new_file method is a hashref of options for this transaction. This module handles a new option called 'meta' which is metadata to be stored along with the file in mogilefs. For example:
$filehandle = $mogc->new_file($path, $class, $size, { meta => { mtime => scalar(time), foo => "bar", }, });
@files = $mogc->list($path) Given a path, returns a list of files contained in that path. Each element of the returned list is a hashref with the following possible keys:
Contains the name of the file
Contains the fully qualified path of the file
True if item is a directory
True if item is a file
Value of mtime metadata field stored with this file.
Size in bytes for this file.
$rv = $mogc->rename($oldpath, $newpath)
Attempts to rename $oldpath to $newpath, returns true on success and false on failure.
To install MogileFS::Client::FilePaths, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MogileFS::Client::FilePaths
CPAN shell
perl -MCPAN -e shell install MogileFS::Client::FilePaths
For more information on module installation, please visit the detailed CPAN module installation guide.