NAME
Data::Tubes::Plugin::Util
DESCRIPTION
This module contains functions to ease using tubes.
FUNCTIONS
- identify
-
identify($args, $opts);
print out an identification for a tube as a log (via Log::Log4perl::Tiny). This function is supposed to be used in tube factories, to print out a message stating that the specific factory is running.
In general,
$args
is the hash reference of arguments that is used as input for the factory. On the other hand,$opts
are options foridentity
itself.Both
$args
and$opts
MUST be hash references. If not provided (orundef
), it is taken from fieldidentification
in$args
.The function tries to figure out the name of the factory that is calling the function itself, so that you don't have to. You can override this automatic detection through option
caller
inside$opts
.The following keys are supported in
$opts
:caller
-
the result of running
CORE::caller
where the input sees fit. This is useful whenever you have a tube factory that relies upon another tube factory, and you want to ensure that the right caller will be used; level
-
hint for
CORE::caller
for automatic detection of the caller. You are probably better off using "caller" instead; loglevel
-
log level to use for emitting the log message;
message
-
a Template::Perlish-compliant string with the message. This template will be expanded with a hash containing the following parameters:
package
filename
line
subroutine
hasargs
wantarray
evaltext
is_require
hints
bitmask
hintsh
-
whatever is available as
caller
(either from$opts
, or automatically detected); name
-
of the tube, tanek from
$args
(or set to string*unknown*
, in case it is undefined in$args
); args
-
what passed as
$args
opts
-
what passed or deduced as
$opts
tp_opts
-
options for Template::Perlish's constructor.
The following options are supported in
$args
:identifier
-
the default value for
$opts
; name
-
the name of the tube, defaults to
*undef*
.
- log_helper
-
my $lh = log_helper($args, $opts);
generate a sub reference that can be useful for emitting log messages, possibly inserted by a factory inside a generated tube. Weight carefully if you really want to use a log helper or if you're just better off using a
logger
from Data::Tubes::Plugin::Plumbing.$args
is supposed to be arguments used to call the tube factory.$opts
contain options forlog_helper
itself.If not defined,
$opts
is taken from fieldlogger
in$args
.The returned sub takes a record as input, and expands a Template::Perlish template. See
message
in the options$opts
below.The following options are available for
$opts
:loglevel
-
log level to use for emitting the log message;
message
-
a Template::Perlish-compliant string with the message. This template will be expanded with a hash containing the following parameters:
args
-
whatever was passed as
$args
; opts
-
whatever passed as
$opts
or taken from$args
in fieldlogger
; record
-
the input record.
tp_opts
-
options for Template::Perlish's constructor.
The following options are recognised from
$args
:logger
-
the default value for
$opts
; name
-
the name of the tube, defaults to
*undef*
.
- read_file
-
my $contents = read_file(%args);
a slurping facility. The following options are available:
binmode
-
parameter for
CORE::binmode
, defaults to:encoding(UTF-8)
; filename
-
the filename (or reference to a string, if you really need it) to slurp data from.
BUGS AND LIMITATIONS
Report bugs either through RT or GitHub (patches welcome).
AUTHOR
Flavio Poletti <polettix@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 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.