Data-Serializer

 view release on metacpan or  search on metacpan

lib/Data/Serializer/Cookbook.pm  view on Meta::CPAN

package Data::Serializer::Cookbook;


use warnings;
use strict;
use vars ('$VERSION');

$VERSION = '0.05';

1;

__END__;
#Documentation follows

=pod

=head1 NAME

Cookbook - Examples of how to use Data::Serializer

=head1 DESCRIPTION

B<Data::Serializer::Cookbook> is a collection of solutions 
for using B<Data::Serializer>.  

=head1 CONVENTIONS

Unless otherwise specified, all examples can be assumed to
begin with:

  use Data::Serializer;

  my $serializer = Data::Serializer->new();

Some examples will show different arguments to the B<new> method, 
where specified simply use that line instead of the simple form above.

=head1 CONVENTIONS for Raw Access

Fort hose who want a straight pass through to the underlying serializer, where 
nothing else is done (no encoding, encryption, compression, etc) there is L<Data::Serializer::Raw(3)>.

These begin like this:

  use Data::Serializer::Raw;

  my $raw_serializer = Data::Serializer::Raw->new();


=head1 Encrypting your data 

You wish to encrypt your data structure, so that it can only be decoded
by someone who shares the same key.  

=head2 Solution

  $serializer->secret('mysecret');

  my $encrypted_hashref = $serializer->serializer($hash);

  ... (in other program) ...

  $serializer->secret('mysecret');

  my $clear_hash = $serializer->deserializer($encrypted_hash);

Note:  You will have to have the Crypt::CBC module installed for
this to work.  

=head1 Compressing your data 

You wish to compress your data structure to cut down on how much
disk space it will take up.

=head2 Solution

  $serializer->compress(1);

  my $compressed_hashref = $serializer->serializer($hash);

  ... (in other program) ...

  my $clear_hash = $serializer->deserializer($compressed_hash);

Note:  You will have to have the Compress::Zlib module installed for
this to work.  Your mileage will vary dramatically depending on what
serializer you use.  Some serializers are already fairly compact.

=head1 You want to read in data serialized outside of Data::Serializer

You need to write a program that can read in data serialized in a 
format other than Data::Serializer.  For example you need to be able
to be able to process data serialized by XML::Dumper.

=head2 Solution

  use Data::Serializer::Raw;

  my $xml_raw_serializer = Data::Serializer::Raw->(serializer => 'XML::Dumper');

  my $hash_ref = $xml_raw_serializer->deserialize($xml_data);

=head1 You want to write serialized data in a form understood outside of Data::Serializer

You need to write a program that can write out data in a format 
other than Data::Serializer.  Or said more generically you need
to write out data in the format native to the underlying serializer.
For our example we will be exporting data using XML::Dumper format.

=head2 Solution

  ues Data::Serializer::Raw;



( run in 0.984 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )