NAME

Parse::Copec64 - ``Cortext Perl Code 64'' serialization format


SYNOPSIS

  use Parse::Copec64;
  $my_data = [ [ [ 1, 2, {} ], { 0=>"a+b", 2=>"abc" }, [], { 1=>2 } ], 0 ];
  $encoded = perl_to_copec64($my_data);
  $decoded = copec64_to_perl($encoded);
  # $encoded contains solid string "A2A4A312hH20_3XjYO2r3abcaH1120"
  # $decoded is a copy (clone) of $my_data
  use Data::NeatDump;
  print dump($my_data, $encoded, $decoded);


DESCRIPTION

Transfering perl data from one environment to another may require encoding perl structure to string and then decoding this string to the source perl structure.

This module introduces string format, suitable for any imaginable transfer, named ``Cortext Perl Code 64''.

This module can be used for cloning perl structures by encoding with the following decoding.

The utf8-flag of a scalar data (if any) is preserved; without a utf8-flag the scalar data is considered to be binary.


CODE-FORMAT

The character set of encoded string contains 64 characters: * digits = 10 characters * english letters 26+26 = 52 characters * underscore and minus signs = 2 characters

So, every encoded character has 6-bit information entropy.


BUGS

Currently supported only normal perl structures, recursively including SCALAR, ARRAY, HASH references and scalars. No loops (self references) allowed.

The functions suppose the characters in perl scalars have 8-bit length (256 characters in charset).

Currently encoded string is one very long line. One can think to insert new-line every 64 characters to get shorter lines.


FUNCTIONS

perl_to_copec64

description
Encodes perl structure to Copec64 string.

parameters
Reference to SCALAR, ARRAY, HASH or scalar to encode.

returns
Encoded string (of one very long line).

Note, if several perl structures are passed, the encoded string will contain all of them chained (one after another).

perl_to_custom_copec64

description
Just like perl_to_copec64, but allows extra features, like breaking the long string into shorter lines, compressing the output, crypting the output and more.

parameters
Option hashref and the rest parameters are like in perl_to_copec64.

Options:

  * compress - boolean, compress the output unconditionally
  * compress_if_helps - boolean, compress the output if reduced
  * compress_or_crypt - boolean, compress the output if reduced or crypt
  * crypt - boolean, slightly crypt the output
  * break - integer, the number of chars in line to break
  * indent - whitespace string, to use as line indentation

returns
Encoded string (of one very long line or shorter lines without the trailing end-of-line).

Note, if several perl structures are passed, the encoded string will contain all of them chained (one after another).

copec64_to_perl

description
Decodes perl structure from Copec64 string.

parameters
Encoded string in Copec64 format.

returns
Reference to SCALAR, ARRAY, HASH or scalar, which is new created perl structure, equivalent to source one.

Note, if given string includes several perl structures (one after another), they all will be returned, when called in list context.