Deprecated.
NAME
Perinci::Sub::Property::result_postfilter - (DEPRECATED) Postfilter function result
VERSION
This document describes version 0.10 of Perinci::Sub::Property::result_postfilter (from Perl distribution Perinci-Sub-Property-result_postfilter), released on 2016-05-11.
SYNOPSIS
# in function metadata
result_postfilter => {
re => 'str', # convert regex object to string
date => 'epoch', # convert date object to an integer Unix time
code => 'str', # convert subroutine to string literal 'CODE'
}
DESCRIPTION
NOTE: The use of this property is now deprecated. Generating filtering code for each function is quite wasteful when there are hundreds or more functions that are wrapped. Instead, see Data::Clean::JSON.
This property specifies postfilters for function result. Currently the focus of this property is converting values that are unsafe when exporting to JSON/YAML.
Value: a hash containing instruction of how to filter. Known keys:
re
(filter regex object)With filter values:
str
(stringify it).date
(date object, such as DateTime in Perl)With filter values:
epoch
(convert to Unix epoch time).code
(subroutine)With filter values:
str
(convert to string literalCODE
).
More sophisticated filtering rules might be specified in the future.
Filtering using generated code can be faster since the code will use for() loop and inline conversion instead of callback for each data item (higher subroutine call overhead).
NOTES
Another alternative is using the encoder's facility, for example the JSON module can convert blessed object:
use JSON 2;
my $encoder = JSON->new->convert_blessed;
{
local *DateTime::TO_JSON = sub { $_[0]->ymd };
print $encoder->encode($doc);
}
But this currently can't convert coderefs. JSON also can't handle circular references, which neither this wrapper property nor the above way can work around.
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/Perinci-Sub-Property-result_postfilter.
SOURCE
Source repository is at https://github.com/perlancar/perl-Perinci-Sub-Property-result_postfilter.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-Sub-Property-result_postfilter
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
SEE ALSO
AUTHOR
perlancar <perlancar@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2016 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.