Steven Haryanto > Perinci-Sub-Property-result_postfilter-0.08 > Perinci::Sub::Property::result_postfilter

Download:
Perinci-Sub-Property-result_postfilter-0.08.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.08   Source  

NAME ^

Perinci::Sub::Property::result_postfilter - (DEPRECATED) Postfilter function result

VERSION ^

version 0.08

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:

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.

SEE ALSO ^

Perinci

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/sharyanto/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.

AUTHOR ^

Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2014 by Steven Haryanto.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: