NAME
Mango::BSON - BSON
SYNOPSIS
use Mango::BSON ':bson';
my $bson = bson_encode bson_doc(now => bson_time, counter => 13);
my $doc = bson_decode $bson;
DESCRIPTION
Mango::BSON is a minimalistic implementation of http://bsonspec.org.
FUNCTIONS
Mango::BSON implements the following functions.
bson_bin
my $generic = bson_bin $bytes;
Create new BSON element of the binary type.
# 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');
bson_code
my $code = bson_code 'function () {}';
Create new BSON element of the code type.
# With scope
bson_code('function () {}')->scope({foo => 'bar'});
bson_decode
my $doc = bson_decode $bson;
Decode BSON into Perl data structures.
bson_doc
my $doc = bson_doc foo => 'bar', baz => 23;
Create new BSON document.
bson_encode
my $bson = bson_encode $doc;
my $bson = bson_encode {};
Encode Perl data structures into BSON.
bson_false
my $false = bson_false;
Create new BSON element of the boolean type false.
bson_length
my $len = bson_length $bson;
Check BSON length prefix.
bson_max
my $max_key = bson_max;
Create new BSON element of the max key type.
bson_min
my $min_key = bson_min;
Create new BSON element of the min key type.
bson_oid
my $oid = bson_oid;
my $oid = bson_oid '1a2b3c4e5f60718293a4b5c6';
Create new BSON element of the object id type.
bson_time
my $now = bson_time;
my $time = bson_time time * 1000;
Create new BSON element of the UTC datetime type.
bson_true
my $true = bson_true;
Create new BSON element of the boolean type true.
bson_ts
my $timestamp = bson_ts 23, 24;
Create new BSON element of the timestamp type.
decode_int32
my $int32 = decode_int32 $bytes;
Decode 32bit integer.
decode_int64
my $int64 = decode_int64 $bytes;
Decode 64bit integer.
encode_cstring
my $bytes = encode_cstring $cstring;
Encode cstring.
encode_int32
my $bytes = encode_int32 $int32;
Encode 32bit integer.
encode_int64
my $bytes = encode_int64 $int64;
Encode 64bit integer.