CBOR::PP::Decode
my $perlvar = CBOR::PP::Decode::decode($binary);
This implements a CBOR encoder in pure Perl.
Scalars that look like unsigned integers are encoded as such. UTF-8 strings and strings that fit 7-bit ASCII (including floats and negatives) are encoded as text. Any other scalar is encoded as binary.
Note that there is no “right way” to determine whether an arbitrary Perl (non-reference) scalar should be encoded as a string or as a number. The above seems a reasonable enough approach.
UTF8-flagged strings are encoded as text; others are encoded as binary. This is a “best-guess” merely; Perl’s UTF8 flag doesn’t reliably indicate whether a given string is a text or a byte string.
undef, Types::Serialiser::true(), and Types::Serialiser::false() are encoded as null, true, and false, respectively.
There is no support for streamed (i.e., indefinite-length) objects.
There is no Perl value that maps to CBOR’s undefined value.
Add canonicalization support.
Optimize as may be feasible.
Gasper Software Consulting (FELIPE)
This code is licensed under the same license as Perl itself.
Returns an object that represents a value and its CBOR tag number. For example, to encode a date/time string, you could do:
my $tagged = tag(0, '2013-03-21T20:04:00Z')
encode() recognizes objects that this function returns and turns them into tagged CBOR values.
encode()
Returns a CBOR string that represents the passed $VALUE.
For now this is only called as a static method but may eventually be an instance method as well, for example, to define options like canonicalization.
To install CBOR::PP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CBOR::PP
CPAN shell
perl -MCPAN -e shell install CBOR::PP
For more information on module installation, please visit the detailed CPAN module installation guide.