NAME
Data::Smile::PP - pure-Perl encoder/decoder for Smile data
SYNOPSIS
use Data::Smile::PP qw( encode_smile decode_smile dump_smile load_smile );
my $bytes = encode_smile( { hello => 'world' } );
my $data = decode_smile( $bytes );
dump_smile( 'example.smile', { answer => 42 } );
my $round_trip = load_smile( 'example.smile' );
DESCRIPTION
This module provides a pure Perl implementation of Smile serialisation. It exports four optional functions:
encode_smiledecode_smiledump_smileload_smile
All option arguments are optional hashrefs. Passing any other kind of reference for options throws an exception.
FUNCTIONS
encode_smile( $data, \%options )
Encodes a Perl data structure into Smile bytes and returns a byte string.
Recognised options:
write_header(boolean, default true)Include the module's Smile transport header before the payload.
shared_names(boolean, default true)Enable the shared-name marker flag when repeated object/hash key names are observed.
shared_values(boolean, default true)Enable the shared short-string-value marker flag when repeated short, non-UTF-8 scalar values are observed.
canonical(boolean, default false)If true, encode hashes/objects with keys sorted lexically.
This is slower, but should (in theory) result in byte-identical output every time, given the same input. If you care about speed, you should be using Data::Smile::XS anyway.
Unknown option keys throw an exception.
decode_smile( $bytes, \%options )
Decodes Smile bytes into Perl data and returns the resulting structure.
Recognised options:
use_bigint(boolean, default true)For Smile big-integer and big-decimal values, return big-number objects (
Math::BigInt/Math::BigFloat) instead of native numeric scalars.require_header(boolean, default false)Require the Smile header to be present. If true and no header is found, decoding throws an exception.
json_bool(boolean, default true)If true, decode booleans as
JSON::PPbooleans (JSON::PP::trueandJSON::PP::false) when available. If false, decode booleans as native Perl booleans.
Unknown option keys throw an exception.
dump_smile( $file, $data, \%options )
Encodes $data using encode_smile and writes the bytes to $file. Returns true on success and false on write/close failure.
$file may be:
a filename string
an open writable filehandle
a
Path::Tinyobjecta
Path::Class::Fileobject
The \%options hashref is passed through to encode_smile, so it accepts the same options and defaults: write_header, shared_names, shared_values, and canonical.
load_smile( $file, \%options )
Reads Smile bytes from $file, decodes them with decode_smile, and returns the resulting data structure.
$file may be:
a filename string
an open readable filehandle
a
Path::Tinyobjecta
Path::Class::Fileobject
The \%options hashref is passed through to decode_smile, so it accepts the same options and defaults: use_bigint, require_header, and json_bool.
BUGS
Please report any bugs to https://github.com/tobyink/p5-data-smile/issues.
SEE ALSO
Data::Smile, Data::Smile::XS, https://github.com/FasterXML/smile-format-specification/blob/master/smile-specification.md (Smile format specification), https://en.wikipedia.org/wiki/Smile_(data_interchange_format).
AUTHOR
Toby Inkster <tobyink@cpan.org>.
COPYRIGHT AND LICENCE
This software is copyright (c) 2026 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
DISCLAIMER OF WARRANTIES
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.