NAME

File::Access::Driver - Convenient File Access with "Batteries included"

DESCRIPTION

File::Access::Driver is a class for convenient file access designed to reduce the code needed to interact with files.

It has grown to a "Batteries included" solution covering the most file access use cases.

It will not produce exceptions but instead report the errors over the getErrorCode() and the getErrorString() methods.

SYNOPSIS

The File::Access::Driver can be used as seen in the "File Write" test:

use File::Access::Driver;

my $driver = File::Access::Driver->new( 'filepath' => $spath . 'files/out/testfile_out.txt' );

# Make sure the file does not exist
is( $driver->Delete(), 1, "File Delete: Delete operation 1 correct" );
is( $driver->Exists(), 0, "File Exist: File does not exist anymore" );

$driver->writeContent(q(This is the multi line content for the test file.

It will be written into the test file.
The file should only contain this text.
Also the file should be created.
));

printf(
    "Test File Exists - File '%s': Write finished with [%d]\n",
    $driver->getFileName(),
    $driver->getErrorCode()
);
printf(
    "Test File Exists - File '%s': Write Report:\n'%s'\n",
    $driver->getFileName(),
    ${ $driver->getReportString() }
);
printf(
    "Test File Exists - File '%s': Write Error:\n'%s'\n",
    $driver->getFileName(),
    ${ $driver->getErrorString() }
);

is( $driver->getErrorCode(),        0,  "Write Error Code: No errors have occurred" );
is( ${ $driver->getErrorString() }, '', "Write Error Message: No errors are reported" );

is( $driver->Exists(), 1, "File Exist: File does exist now" );
isnt( $driver->getFileSize(), 0, "File Size: File is not empty anymore" );

METHODS

Constructor

new ( [ CONFIGURATIONS ] )

This is the constructor for a new File::Access::Driver object.

Parameters:

CONFIGURATIONS

Key and value pairs containing the configurations.

Recognized fields:

filedirectory - The directory where the file is located.

filename - The base name of the file.

filepath - The complete path with directory and file base name.

See Method setFileDirectory()

See Method setFileName()

setFileDirectory ( DIRECTORY )

This method sets the directory where the file is located.

Parameters:

DIRECTORY

The directory where the file is located.

If the directory does not end on a slash / it will be appended.

setFileName ( NAME )

This method sets the base name of the file.

This will also close open file handles and free in-memory cache.

Parameters:

NAME

The base name of the file.

See Method Clear()

setFilePath ( PATH )

This method sets the complete path of the file.

Parameters:

PATH

The complete path of the file.

This will split the PATH and call setFileDirectory() with the directory and setFileName() with the file base name.

See Method setFileDirectory()

See Method setFileName()

setBuffered ( BUFFERED )

This method enables or disables the in-memory buffer.

Parameters:

BUFFERED

If the in-memory buffer should be enabled or disabled. (Possible values: 0 | 1 )

setPersistent ( PERSISTENT )

This method enables or disables the persistent mode.

If the persistent mode is enabled the file is kept open.

Parameters:

PERSISTENT

If the filehandle should be kept open. (Possible values: 0 | 1 )

Create ()

This method will create an empty file.

If the file already exists it will be truncated.

Truncate ()

This method will empty an existing file.

If the file does not exist it will be created.

Delete ()

This method deletes the file from the file system.

It will return 1 if the file could be deleted.

If it could not be deleted it sets the Error Code and the Error String.

Returns:

It returns 1 if the file could be deleted or if it did not exist.

Or 0 if the file could not be deleted.

Clear ()

This method closed the file handle and frees the in-memory buffer and resets also the in-memory file attributes.

clearErrors ()

Clear the error and activity report and reset the error code.

freeResources ()

This method closed the file handle and frees the in-memory buffer.

getFileDirectory ()

This method returns the directory of the file.

Returns:

The directory of the file. It is terminated with a trailing slash / .

getFileName ()

This method returns the base name of the file.

Returns:

The base name of the file.

getFilePath ()

This method returns the complete path of the file.

Returns:

The complete path of the file.

Exists ()

This method checks if the file exists in the file system.

Returns:

It returns 1 if the file exists otherwise 0 .