Name

Connector::Builtin::File::Path

Description

Highly configurable file writer/reader.

Parameters

LOCATION

The base directory where the files are located. This parameter is mandatory.

file

Pattern for Template Toolkit to build the filename. The path components are available in the key ARGS. In set mode the unfiltered data is available in key DATA.

content

Pattern for Template Toolkit to build the content. The data is passed "as is". If data is a scalar, it is wrapped into a hash using DATA as key.

ifexists
  • append: opens the file for appending write.

  • fail: call die

  • silent: fail silently.

  • replace: replace the file with the new content.

mode

Filesystem permissions to apply to the file when a file is written using the set method. Must be given in octal notation, e.g. 0644. Default is to not set the permissions and rely on the systems umask.

user / group

Name of a user / group that the file should belong to.

Supported Methods

set

Write data to a file.

$conn->set('filename', { NAME => 'Oliver', 'ROLE' => 'Administrator' });

See the file parameter how to control the filename. By default, files are silently overwritten if they exist. See the ifexists parameter for an alternative behaviour.

get

Fetch data from a file. See the file parameter how to control the filename.

my $data = $conn->get('filename');

Example

my $conn = Connector::Builtin::File::Path->new({
   LOCATION: /var/data/
   file: [% ARGS.0 %].txt
   content: Hello [% NAME %]
});

$conn->set('test', { NAME => 'Oliver' });

Results in a file /var/data/test.txt with the content Hello Oliver.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 268:

You forgot a '=back' before '=head1'