Data::Embed::Writer - embed arbitrary data in a file - writer class
Constructor.
my $w = Data::Embed::Writer->new(%args); my $w = Data::Embed::Writer->new(\%args);
The difference between the two forms is that you can pass either key-value pairs, or a hash reference with key-value pairs. Acceptable keys are:
output
Optional parameter, where to send output data. If not present, undefined, empty or set to the string -, then standard output will be considered.
-
If a filehandle is provided, it is expected to be seekable and will also be binmode-d in :raw mode.
binmode
:raw
input
Optional parameters, where to get initial data:
if not present, no previous input will be considered.
if equal to the string -, the standard input will be considered
if equal to some other string, it will be considered a filename
if a reference to a scalar, it will be open()ed
open()
otherwise it will be considered a filehandle
This method throws an exception in case of errors. Returns a new object in case of success.
Catchall method for adding a section into the target file.
Expects a list of key-value pairs or a hash reference in input. The recognised keys are:
data
a scalar from where data will be read. If you have a huge amount of data, it's better to use the filename key above passing a reference to the scalar holding the data.
filename
do-what-I-mean so that you can pass:
the string -, in which case standard input is assumed
any other string, or a reference to a scalar, in which case it is treated as a filename (for the reference, it is the way to "read" from the scalar)
otherwise, the input is assumed to be a filehandle
inputs
a reference to an array containing hash references, each with fields as in this list, except for inputs itself (i.e. this options is not recursive)
name
the name to associate to the section, optionally. If missing it will be set to the empty string
a filename or a reference to a scalar where data will be read from
fh
the filehandle from where data should be taken. The filehandle will be exausted starting from its current position
Options fh, filename and data are exclusive and will be considered in the order above (first come, first served).
This method does not return anything.
Add one section from either a file or a reference to a scalar holding the data (whatever suits open anyway).
open
Takes two positional parameters:
name of the section (set to the empty string if undefined)
filename or reference to the data
Returns nothing.
Add one section from a scalar holding the data.
scalar holding the data to be added
Add one section from a filehandle holding the data. The filehandle will be read from its current position up to the end.
filehandle
Write the index of the contained sections out to the output channel. Doing this invalidates the object, so you should not perform any further action after.
This gets automatically called upon object destruction, if not previously called.
Flavio Poletti <polettix@cpan.org>
Copyright (C) 2014-2016 by Flavio Poletti <polettix@cpan.org>
This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
To install Data::Embed, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Embed
CPAN shell
perl -MCPAN -e shell install Data::Embed
For more information on module installation, please visit the detailed CPAN module installation guide.