Perinci::Result::Format - Format envelope result
This document describes version 0.45 of Perinci::Result::Format (from Perl distribution Perinci-Result-Format), released on 2015-11-29.
This module formats enveloped result to YAML, JSON, etc. It uses Data::Format::Pretty for the backend. It is used by other Perinci modules like Perinci::CmdLine and Perinci::Access::HTTP::Server.
The default supported formats are:
json
Using Data::Format::Pretty::CompactJSON.
json-pretty
Using Data::Format::Pretty::JSON.
text-simple
Using Data::Format::Pretty::SimpleText.
text-pretty
Using Data::Format::Pretty::Text.
text
Using Data::Format::Pretty::Console.
yaml
Using Data::Format::Pretty::YAML.
perl
Using Data::Format::Pretty::Perl.
phpserialization
Using Data::Format::Pretty::PHPSerialization.
ruby
Using Data::Format::Pretty::Ruby.
Contains a mapping between format names and Data::Format::Pretty::* module names + MIME type.
Decorations include color or other markup, which might make a data structure like JSON or YAML string become invalid JSON/YAML. This should be turned off if one wants to send the formatting over network.
If enabled, cleansing will be done to data to help make sure that data does not contain item that cannot be handled by formatter. for example, JSON format cannot handle circular references or complex types other than hash/array.
None is currently exported/exportable.
Format enveloped result $res with format named $format.
$res
$format
Result metadata ($res->[3]) is also checked for key named format_options. The value should be a hash like this { FORMAT_NAME => OPTS, ... }. FORMAT_NAME can be any to mean any format. This way, function results can specify the details of formatting. An example enveloped result:
$res->[3]
format_options
{ FORMAT_NAME => OPTS, ... }
any
[200, "OK", ["foo", "bar", "baz"], { format_options => { "text" => {list_max_columns=>1}, "text-pretty" => {list_max_columns=>1}, } }]
The above result specifies that if it is displayed using text or text-pretty format, it should be displayed in one columns instead of multicolumns.
property: format_options => HASH
Simply:
my @supported_formats = keys %Perinci::Result::Format::Formats;
First make sure that Data::Format::Pretty::<FORMAT> module is available for your format. Look on CPAN. If it's not, i't also not hard to create one.
Then, add your format to %Perinci::Result::Format::Formats hash:
use Perinci::Result::Format; # this means format named 'xml' will be handled by Data::Format::Pretty::XML $Perinci::Result::Format::Formats{xml} = ['XML', 'text/xml'];
Data::Format::Pretty
Please visit the project's homepage at https://metacpan.org/release/Perinci-Result-Format.
Source repository is at https://github.com/sharyanto/perl-Perinci-Result-Format.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-Result-Format
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.
perlancar <perlancar@cpan.org>
This software is copyright (c) 2015 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::Result::Format, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perinci::Result::Format
CPAN shell
perl -MCPAN -e shell install Perinci::Result::Format
For more information on module installation, please visit the detailed CPAN module installation guide.