Data::Serializer(3pm) | User Contributed Perl Documentation | Data::Serializer(3pm) |
Data::Serializer:: - Modules that serialize data structures
use Data::Serializer; $obj = Data::Serializer->new(); $obj = Data::Serializer->new( serializer => 'Storable', digester => 'MD5', cipher => 'DES', secret => 'my secret', compress => 1, ); $serialized = $obj->serialize({a => [1,2,3],b => 5}); $deserialized = $obj->deserialize($serialized); print "$deserialized->{b}\n";
Provides a unified interface to the various serializing modules currently available. Adds the functionality of both compression and encryption.
By default Data::Serializer(3) adds minor metadata and encodes serialized data structures in it's own format. If you are looking for a simple unified pass through interface to the underlying serializers then look into Data::Serializer::Raw(3) that comes bundled with Data::Serializer(3).
$obj = Data::Serializer->new(); $obj = Data::Serializer->new( serializer => 'Data::Dumper', digester => 'SHA-256', cipher => 'Blowfish', secret => undef, portable => '1', compress => '0', serializer_token => '1', options => {}, );
new is the constructor object for Data::Serializer(3) objects.
$serialized = $obj->serialize({a => [1,2,3],b => 5});
Serializes the reference specified.
Will compress if compress is a true value.
Will encrypt if secret is defined.
$deserialized = $obj->deserialize($serialized);
Reverses the process of serialization and returns a copy of the original serialized reference.
$serialized = $obj->freeze({a => [1,2,3],b => 5});
$deserialized = $obj->thaw($serialized);
$serialized = $obj->raw_serialize({a => [1,2,3],b => 5});
This is a straight pass through to the underlying serializer, nothing else is done. (no encoding, encryption, compression, etc)
If you desire this functionality you should look at Data::Serializer::Raw(3) instead, it is faster and leaner.
$deserialized = $obj->raw_deserialize($serialized);
This is a straight pass through to the underlying serializer, nothing else is done. (no encoding, encryption, compression, etc)
If you desire this functionality you should look at Data::Serializer::Raw(3) instead, it is faster and leaner.
$obj->secret('mysecret');
Changes setting of secret for the Data::Serializer(3) object. Can also be set in the constructor. If specified than the object will utilize encryption.
Aids in the portability of serialized data.
If you desire this functionality you should look at Data::Serializer::Raw(3) instead, it is faster and leaner.
Default is to use Data::Dumper.
Each serializer has its own caveat's about usage especially when dealing with cyclical data structures or CODE references. Please see the appropriate documentation in those modules for further information.
The b64 option uses Base64 encoding provided by MIME::Base64(3), but strips out newlines.
my $obj = Data::Serializer->new(serializer => 'Config::General', options => { -LowerCaseNames => 1, -UseApacheInclude => 1, -MergeDuplicateBlocks => 1, -AutoTrue => 1, -InterPolateVars => 1 }, ) or die "$!\n"; or my $obj = Data::Serializer->new(serializer => 'XML::Dumper', options => { dtd => 1, } ) or die "$!\n";
$obj->store({a => [1,2,3],b => 5},$file, [$mode, $perm]); or $obj->store({a => [1,2,3],b => 5},$fh);
Serializes the reference specified using the serialize method and writes it out to the specified file or filehandle.
If a file path is specified you may specify an optional mode and permission as the next two arguments. See IO::File for examples.
Trips an exception if it is unable to write to the specified file.
my $ref = $obj->retrieve($file); or my $ref = $obj->retrieve($fh);
Reads first line of supplied file or filehandle and returns it deserialized.
Neil Neely <neil@neely.cx>.
Feature requests are certainly welcome.
http://neil-neely.blogspot.com/
Please report all bugs here:
http://rt.cpan.org/Public/Dist/Display.html?Name=Data-Serializer
Extend the persistent framework. Perhaps Persistent::Base(3) framework would be useful to explore further. Volunteers for putting this together would be welcome.
Copyright (c) 2001-2020 Neil Neely. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available.
See http://www.perl.com/language/misc/Artistic.html
Gurusamy Sarathy and Raphael Manfredi for writing MLDBM(3), the module which inspired the creation of Data::Serializer(3).
And thanks to all of you who have provided the feedback that has improved this module over the years.
In particular I'd like to thank Florian Helmberger, for the numerous suggestions and bug fixes.
This module is dedicated to my beautiful wife Erica.
<http://github.com/neilneely/Data-Serializer/>
2022-10-22 | perl v5.36.0 |