Data::Record::Serialize::Role::Base - Base Role for Data::Record::Serialize
version 0.21
Data::Record::Serialize::Role::Base is the base role for Data::Record::Serialize. It serves the place of a base class, except as a role there is no overhead during method lookup
Data::Record::Serialize::Role::Base
types
A hash or array mapping input field names to types (N, I, S). If an array, the fields will be output in the specified order, provided the encoder permits it (see below, however). For example,
N
I
S
# use order if possible types => [ c => 'N', a => 'N', b => 'N' ] # order doesn't matter types => { c => 'N', a => 'N', b => 'N' }
If fields is specified, then its order will override that specified here.
fields
To understand how this attribute works in concert with "fields" and "default_type", please see "Fields and their types".
default_type
If set, output fields whose types were not specified via the types attribute will be assigned this type. To understand how this attribute works in concert with "fields" and "types", please see "Fields and their types".
Which fields to output. It may be one of:
An array containing the input names of the fields to be output. The fields will be output in the specified order, provided the encoder permits it.
The string all, indicating that all input fields will be output.
all
Unspecified or undefined.
To understand how this attribute works in concert with "types" and "default_type", please see "Fields and their types" in Data::Record::Serialize.
Specify which fields should be set to undef if they are empty. Sinks should encode undef as the null value. By default, no fields are nullified.
undef
null
nullify may be passed:
an array
It should be a list of input field names. These names are verified against the input fields after the first record is read.
a code ref
The coderef is passed the object, and should return a list of input field names. These names are verified against the input fields after the first record is read.
a boolean
If true, all field names are added to the list. When false, the list is emptied.
During verification, a Data::Record::Serialize::Error::Role::Base::fields error is thrown if non-existent fields are specified. Verification is not performed until the next record is sent (or the "nullified" method is called), so there is no immediate feedback.
Data::Record::Serialize::Error::Role::Base::fields
format_fields
A hash mapping the input field names to either a sprintf style format or a coderef. This will be applied prior to encoding the record, but only if the format attribute is also set. Formats specified here override those specified in format_types.
sprintf
format
format_types
The coderef will be called with the value to format as its first argument, and should return the formatted value.
A hash mapping a field type (N, I, S) to a sprintf style format or a coderef. This will be applied prior to encoding the record, but only if the format attribute is also set. Formats specified here may be overridden for specific fields using the format_fields attribute.
rename_fields
A hash mapping input to output field names. By default the input field names are used unaltered.
If true, format the output fields using the formats specified in the format_fields and/or format_types options. The default is false.
returns true if "types" has been set.
returns true if "fields" has been set.
$array_ref = $s->output_fields;
The names of the transformed output fields, in order of output (not obeyed by all encoders);
returns true if "nullify" has been set.
$fields = $obj->nullified;
Returns a list of fields which are checked for empty values (see "nullify").
This will return undef if the list is not yet available (for example, if fields names are determined from the first output record and none has been sent).
If the list of fields is available, calling nullified may result in verification of the list of nullified fields against the list of actual fields. A disparity will result in an exception of class Data::Record::Serialize::Error::Role::Base::fields.
$array_ref = $s->numeric_fields;
The input field names for those fields deemed to be numeric.
$hash = $s->type_index;
A hash, keyed off of field type or category. The values are an array of field names. Don't edit this!.
The hash keys are:
numeric
N and I.
not_string
Everything but S.
$hash_ref = $s->output_types;
The mapping between output field name and output field type. If the encoder has specified a type map, the output types are the result of that mapping.
Please report any bugs or feature requests to bug-data-record-serialize@rt.cpan.org or through the web interface at: https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Record-Serialize
Source is available at
https://gitlab.com/djerius/data-record-serialize
and may be cloned from
https://gitlab.com/djerius/data-record-serialize.git
Please see those modules/websites for more information related to this module.
Data::Record::Serialize
Diab Jerius <djerius@cpan.org>
This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory.
This is free software, licensed under:
The GNU General Public License, Version 3, June 2007
To install Data::Record::Serialize, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Record::Serialize
CPAN shell
perl -MCPAN -e shell install Data::Record::Serialize
For more information on module installation, please visit the detailed CPAN module installation guide.