PLON - Serialize object to Perl code
use PLON; my $plon = encode_plon([]); # $plon is `[]`
PLON is yet another serialization library for Perl5, has the JSON.pm like interface.
I need data dumper library supports JSON::XS/JSON::PP like interface. I use JSON::XS really hard. Then, I want to use other serialization library with JSON::XS/JSON::PP's interface.
Data::Dumper escapes multi byte chars. When I want copy-and-paste from Data::Dumper's output to my test code, I need to un-escape \x{5963} by my hand. PLON.pm don't escape multi byte characters by default.
\x{5963}
This release is a prototype. Every API will change without notice. (But, I may not remove encode_plon($scalar) interface. You can use this.)
encode_plon($scalar)
I need your feedback. If you have ideas or comments, please report to Github Issues.
The object oriented interface lets you configure your own encoding or decoding style, within the limits of supported formats.
Creates a new PLON object that can be used to de/encode PLON strings. All boolean flags described below are by default disabled.
$plon = $plon->pretty([$enabled])
This enables (or disables) all of the indent, space_before and space_after (and in the future possibly more) flags in one call to generate the most readable (or most compact) form possible.
indent
space_before
space_after
$plon->ascii([$enabled])
my $enabled = $plon->get_ascii()
$plon = $plon->ascii([$enable]) $enabled = $plon->get_ascii
If $enable is true (or missing), then the encode method will not generate characters outside the code range 0..127. Any Unicode characters outside that range will be escaped using either a \x{XXXX} escape sequence.
If $enable is false, then the encode method will not escape Unicode characters unless required by the PLON syntax or other flags. This results in a faster and more compact format.
PLON->new->ascii(1)->encode([chr 0x10401]) => ["\x{10401}"]
$plon->deparse([$enabled])
my $enabled = $plon->get_deparse()
If $enable is true (or missing), then the encode method will de-parse the code by B::Deparse. Otherwise, encoder generates sub { "DUMMY" } like Data::Dumper.
sub { "DUMMY" }
$plon->canonical([$enabled])
my $enabled = $plon->get_canonical()
If $enable is true (or missing), then the "encode" method will output PLON objects by sorting their keys. This is adding a comparatively high overhead.
Copyright (C) Tokuhiro Matsuno.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Tokuhiro Matsuno <tokuhirom@gmail.com>
To install PLON, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PLON
CPAN shell
perl -MCPAN -e shell install PLON
For more information on module installation, please visit the detailed CPAN module installation guide.