Mango::BSON - BSON
use Mango::BSON ':bson'; my $bson = bson_encode bson_doc(now => bson_time, counter => 13); my $doc = bson_decode $bson;
Mango::BSON is a minimalistic implementation of http://bsonspec.org.
In addition to a bunch of custom BSON data types it supports normal Perl data types like Scalar, Regexp, undef, Array reference, Hash reference and will try to call the TO_JSON method on blessed references, or stringify them if it doesn't exist. Scalar references will be used to generate booleans, based on if their values are true or false.
Scalar
Regexp
undef
Array
Hash
TO_JSON
Mango::BSON implements the following functions.
my $bin = bson_bin $bytes;
Create new BSON element of the binary type, defaults to the generic binary subtype.
generic
# Function bson_bin($bytes)->type('function'); # MD5 bson_bin($bytes)->type('md5'); # UUID bson_bin($bytes)->type('uuid'); # User defined bson_bin($bytes)->type('user_defined');
my $code = bson_code 'function () {}';
Create new BSON element of the code type.
# With scope bson_code('function () {}')->scope({foo => 'bar'});
my $doc = bson_decode $bson;
Decode BSON into Perl data structures.
my $doc = bson_doc; my $doc = bson_doc foo => 'bar', baz => 23;
Create new BSON document, defaults to an empty ordered hash.
my $bson = bson_encode $doc; my $bson = bson_encode {};
Encode Perl data structures into BSON.
my $false = bson_false;
Create new BSON element of the boolean type false.
my $len = bson_length $bson;
Check BSON length prefix.
my $max_key = bson_max;
Create new BSON element of the max key type.
my $min_key = bson_min;
Create new BSON element of the min key type.
my $oid = bson_oid; my $oid = bson_oid '1a2b3c4e5f60718293a4b5c6';
Create new BSON element of the object id type, defaults to generating a new unique object id.
my $now = bson_time; my $time = bson_time time * 1000;
Create new BSON element of the UTC datetime type, defaults to milliseconds since the UNIX epoch.
my $true = bson_true;
Create new BSON element of the boolean type true.
my $timestamp = bson_ts 23, 24;
Create new BSON element of the timestamp type.
my $int32 = decode_int32 $bytes;
Decode 32bit integer.
my $int64 = decode_int64 $bytes;
Decode 64bit integer.
my $bytes = encode_cstring $cstring;
Encode cstring.
my $bytes = encode_int32 $int32;
Encode 32bit integer.
my $bytes = encode_int64 $int64;
Encode 64bit integer.
Mango, Mojolicious::Guides, http://mojolicio.us.
To install Mango, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mango
CPAN shell
perl -MCPAN -e shell install Mango
For more information on module installation, please visit the detailed CPAN module installation guide.