BSON
view release on metacpan or search on metacpan
devel/bson-types-survey.md view on Meta::CPAN
### BSON::Binary
$obj = BSON::Binary->new( $data, $subtype );
This class has the following methods:
* new â subtype defaults to `SUBTYPE_GENERIC`
* data â returns an *array reference* to bytes (oy!); also read-write (oy!)
* type â returns the subtype
* to_s â returns the data as a BSON fragment (based on the data method, so
horribly inefficient); also undocumented
It is implemented as a hash reference. The `$data` given to new is split
into a new `data` element (array reference). String overloading maps to
the `to_s` function.
### Mango::BSON::Binary
$obj = Mango::BSON::Binary->new( data => $data, type => $subtype);
t/legacy/10-bson.t view on Meta::CPAN
is_deeply(
[ unpack "C*", $bson ],
\@expected_bytes,
'Regex encode'
);
my $hash = decode( $bson );
is(ref $hash->{a}, 'BSON::Regex');
is(ref $hash->{b}, 'BSON::Regex');
SKIP: {
skip "Comparing regexes is fragile before 5.10", 1 if $] lt 5.010;
$hash->{$_} = $hash->{$_}->try_compile for qw/a b/;
for (qw/a b/) {
is_deeply(
[ re::regexp_pattern( $hash->{$_} ) ],
[ re::regexp_pattern( $h{$_} ) ],
"Regex decode of key $_",
);
}
}
t/legacy/10-bson.t view on Meta::CPAN
40, 63, 58, 40, 63, 58, 91, 69, 93, 41, 40, 63,
58, 40, 63, 58, 91, 43, 45, 93, 63, 41, 40, 63,
58, 91, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
93, 43, 41, 41, 124, 41, 41, 0, 105, 0, 0
],
'real num regex'
);
$hash = decode( $bson );
is(ref $hash->{a}, 'BSON::Regex');
SKIP: {
skip "Comparing regexes is fragile before 5.10", 2 if $] lt 5.010;
$hash->{a} = $hash->{a}->try_compile;
# after try_compile, "i" flags are put into the regex, so we must
# do the same with the original
my ($p,$f) = re::regexp_pattern($h{a});
$h{a} = qr{(?$f:$p)};
is_deeply(
[ re::regexp_pattern( $hash->{a} ) ],
[ re::regexp_pattern( $h{a} ) ],
"Regex decode of key a",
);
( run in 1.923 second using v1.01-cache-2.11-cpan-b16cb0d3907 )