Perinci::Sub::Property::result_postfilter - (DEPRECATED) Postfilter function result
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.
# 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' }
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)
re
With filter values: str (stringify it).
str
date (date object, such as DateTime in Perl)
date
With filter values: epoch (convert to Unix epoch time).
epoch
code (subroutine)
code
With filter values: str (convert to string literal CODE).
CODE
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).
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.
Please visit the project's homepage at https://metacpan.org/release/Perinci-Sub-Property-result_postfilter.
Source repository is at https://github.com/perlancar/perl-Perinci-Sub-Property-result_postfilter.
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.
Perinci
perlancar <perlancar@cpan.org>
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.
To install Perinci::Sub::Property::result_postfilter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perinci::Sub::Property::result_postfilter
CPAN shell
perl -MCPAN -e shell install Perinci::Sub::Property::result_postfilter
For more information on module installation, please visit the detailed CPAN module installation guide.