<<

NAME

MT::FileMgr - Base class for file management drivers

SYNOPSIS

    use MT::FileMgr;
    my $fmgr = MT::FileMgr->new('Local')
        or die MT::FileMgr->errstr;
    defined(my $bytes = $fmgr->put($src, $dest))
        or die $fmgr->errstr;

DESCRIPTION

MT::FileMgr is a base class for file management driver implementations; it provides an abstraction of file management such that other Movable Type classes do not have to worry if files should be built locally or through FTP. For example, the process that rebuilds a user's site only has to build the content, then pass it off to the MT::FileMgr driver; it does not have to worry whether the user's site is hosted locally or on an FTP server. MT::FileMgr dispatches control to the appropriate driver, and the content is pushed to wherever it needs to be pushed.

USAGE

MT::FileMgr->new($type [, @args ])

Loads the driver class $type (either FTP or Local, currently) and returns a new file manager object blessed into the appropriate driver subclass.

@args is optional; it will be passed along to the subclass's init method, for driver-specific initialization. For example, the FTP driver requires the FTP host, username, and password in @args, whereas the Local host does not require anything.

If an initialization error occurs, returns undef; see "ERROR HANDLING", below.

$fmgr->init()

This is an internal method called by MT::FileMgr->new that initializes an "instance" in MT::ConfigMgr as the cfg attribute.

$fmgr->put($src, $dest [, $type ])

Puts the contents of the file $src in the path $dest. $src can be either a filehandle of the path to a local file; $dest must be a path to a file, either local or remote (depending on the driver).

$type is optional and defines whether the put is for an uploaded file or for an output HTML file; this tells the FileMgr drivers what mode to write the files in, what umask settings to use, etc. The two values for $type are upload and output; output is the default.

Returns the number of bytes "put" (can be 0).

On error, returns undef; see "ERROR HANDLING", below.

$fmgr->put_data($data, $dest [, $type ])

Puts the block of data $data in the path $dest. $src should be a scalar containing the data, and $dest should be a path to a file, either local or remote (depending on the driver).

$type is optional and defines whether the put_data is for an uploaded file or for an output HTML file; this tells the FileMgr drivers what mode to write the files in, what umask settings to use, etc. The two values for $type are upload and output; output is the default.

Returns the number of bytes "put" (can be 0).

On error, returns undef; see "ERROR HANDLING", below.

$fmgr->get_data($src [, $type ])

Gets a block of data from the path $src; returns the block of data. $src should be a path to a file, either local or remote (depending on the driver).

$type is optional and defines whether the get_data is for an uploaded file or for an output HTML file; this tells the FileMgr drivers what mode to write the files in, what umask settings to use, etc. The two values for $type are upload and output; output is the default.

On error, returns undef; see "ERROR HANDLING", below.

$fmgr->exists($path)

Returns true if the file or directory $path exists, false otherwise.

$fmgr->mkpath($path)

Creates the path $path recursively; in other words, if any of the directories in the path do not exist, they are created. Returns true on success.

On error, returns undef; see "ERROR HANDLING", below.

$fmgr->rename($src, $dest)

Renames the file or directory $src to $dest. Returns true on success.

On error, returns undef; see "ERROR HANDLING", below.

content_is_updated()

Return one (1).

$fmgr->is_handle($file)

Return the file descriptor of file or undef if not found.

ERROR HANDLING

On an error, all of the above methods (except exists) return undef, and the error message can be obtained by calling the method errstr on the class or the object (depending on whether the method called was a class method or an instance method).

For example, called on a class name:

    my $fmgr = MT::FileMgr->new('Local')
        or die MT::FileMgr->errstr;

Or, called on an object:

    defined(my $bytes = $fmgr->put($src, $dest))
        or die $fmgr->errstr;

AUTHOR & COPYRIGHT

Please see "AUTHOR & COPYRIGHT" in MT.

<<