PP, so that modules can pick up right version of helpers
use BSON::Types (); # loads types for extjson inflation
#--------------------------------------------------------------------------#
# public
method inflate_extjson (DEPRECATED)
#pod
#pod This legacy method does not follow the L<MongoDB Extended JSON|https://github.com/mongodb/specifications/blob/master/source/extended-json.rst>
#pod specif
ication.
#pod
#pod Use L</extjson_to_perl> instead.
#pod
#pod =cut
sub inflate_extjson {
my ( $self, $hash ) = @_;
for my $k ( keys %$hash ) {
my $v = $hash->{$k};
if ( subst
TO_JSON
#pod
#pod Returns Base64 encoded string equivalent to the data attribute.
#pod
#pod If the C<BSON_EXTJSON> option is true, it will instead be compatible with
#pod MongoDB's L<extended JSON|ht
ce/extended-json.rst>
#pod format, which represents it as a document as follows:
#pod
#pod {"$binary" : { "base64": "<base64 data>", "subType" : "<type>"} }
#pod
#pod =cut
sub TO_JSON {
retur
n MIME::Base64::encode_base64($_[0]->{data}, "") unless $ENV{BSON_EXTJSON};
my %data;
tie( %data, 'Tie::IxHash' );
$data{base64} = MIME::Base64::encode_base64($_[0]->{data}, "");
$dat
TO_JSON
#pod
#pod If the C<BSON_EXTJSON> option is true, returns a hashref compatible with
#pod MongoDB's L<extended JSON|https://github.com/mongodb/specifications/blob/master/source/extended-json.rs
e C<BSON_EXTJSON> option is false, an error is thrown, as this value
#pod can't otherwise be represented in JSON.
#pod
#pod =cut
sub TO_JSON {
require BSON;
if ( $ENV{BSON_EXTJSON} ) {
$scope'} = BSON->perl_to_extjson($_[0]->{scope})
if defined $_[0]->{scope};
return \%data;
}
Carp::croak( "The value '$_[0]' is illegal in JSON" );
}
1;
=pod
=encoding
TO_JSON
#pod
#pod If the C<BSON_EXTJSON> option is true, returns a hashref compatible with
#pod MongoDB's L<extended JSON|https://github.com/mongodb/specifications/blob/master/source/extended-json.rs
pod If the C<BSON_EXTJSON> option is false, an error is thrown, as this value
#pod can't otherwise be represented in JSON.
#pod
#pod =cut
sub TO_JSON {
if ( $ENV{BSON_EXTJSON} ) {
my %dat
return { '$timestamp' => \%data };
}
Carp::croak( "The value '$_[0]' is illegal in JSON" );
}
sub _cmp {
my ( $l, $r, $swap ) = @_;
if ( !defined($l) || !defined($r) ) {
TO_JSON
#pod
#pod If the C<BSON_EXTJSON> option is true, returns a hashref compatible with
#pod MongoDB's L<extended JSON|https://github.com/mongodb/specifications/blob/master/source/extended-json.rs
pod If the C<BSON_EXTJSON> option is false, an error is thrown, as this value
#pod can't otherwise be represented in JSON.
#pod
#pod =cut
sub TO_JSON {
if ( $ENV{BSON_EXTJSON} ) {
return
{ '$maxKey' => 1 };
}
croak( "The value '$_[0]' is illegal in JSON" );
}
1;
=pod
=encoding UTF-8
=head1 NAME
BSON::MaxKey - BSON type wrapper for MaxKey
=head1 VERSION
version v1.12.2
d =method TO_JSON
#pod
#pod Returns a string formatted by L</as_iso8601>.
#pod
#pod If the C<BSON_EXTJSON> option is true, it will instead be compatible with
#pod MongoDB's L<extended JSON|https://git
er/source/extended-json.rst>
#pod format, which represents it as a document as follows:
#pod
#pod
#pod If the C<BSON_EXTJSON> environment variable is true and the
#pod C<BSON_EXTJSON_RELAXED> environm
rns a hashref
#pod compatible with
#pod MongoDB's L<extended JSON|https://github.com/mongodb/specifications/blob/master/source/extended-json.rst>
#pod format, which represents it as a document as foll
TO_JSON
#pod
#pod If the C<BSON_EXTJSON> option is true, returns a hashref compatible with
#pod MongoDB's L<extended JSON|https://github.com/mongodb/specifications/blob/master/source/extended-json.rs
C<BSON_EXTJSON> option is false, an error is thrown, as this value
#pod can't otherwise be represented in JSON.
#pod
#pod =cut
sub TO_JSON {
my $self = shift;
if ( $ENV{BSON_EXTJSON} ) {
d = $self->id;
if (ref $id) {
$id = $id->TO_JSON;
}
else {
$id = BSON->perl_to_extjson($id);
}
my %data;
tie( %data, 'Tie::IxH
@data = @{ $self->data };
return pack( 'l<C*', scalar(@data), $self->type, @data );
}
sub TO_JSON {
my %data;
tie( %data, 'Tie::IxHash' );
$data{base64} = $_[0]->to_s;
$data{subTy
ongly encouraged to use L<BSON::Bytes> instead.
=for Pod::Coverage new data type subtype to_s TO_JSON
=head1 AUTHORS
=over 4
=item *
David Golden <david@mongodb.com>
=item *
Stefan G. <minimali
TO_JSON
#pod
#pod If the C<BSON_EXTJSON> option is true, returns a hashref compatible with
#pod MongoDB's L<extended JSON|https://github.com/mongodb/specifications/blob/master/source/extended-json.rs
pod If the C<BSON_EXTJSON> option is false, an error is thrown, as this value
#pod can't otherwise be represented in JSON.
#pod
#pod =cut
sub TO_JSON {
if ( $ENV{BSON_EXTJSON} ) {
return
{ '$minKey' => 1 };
}
croak( "The value '$_[0]' is illegal in JSON" );
}
1;
=pod
=encoding UTF-8
=head1 NAME
BSON::MinKey - BSON type wrapper for MinKey
=head1 VERSION
version v1.12.2
O_JSON
#pod
#pod Returns a string for this OID, with the OID given as 24 hex digits.
#pod
#pod If the C<BSON_EXTJSON> option is true, it will instead be compatible with
#pod MongoDB's L<extended JSON|
d-json.rst>
#pod format, which represents it as a document as follows:
#pod
#pod {"$oid" : "012345678901234567890123"}
#pod
#pod =cut
sub TO_JSON {
return $_[0]->hex unless $ENV{BSON_EXTJSON}
.
=head2 TO_JSON
Returns a string for this OID, with the OID given as 24 hex digits.
If the C<BSON_EXTJSON> option is true, it will instead be compatible with
MongoDB's L<extended JSON|https://gith
od TO_JSON
#pod
#pod On a 64-bit perl, returns the value as an integer. On a 32-bit Perl, it
#pod will be returned as a Math::BigInt object, which will
#pod fail to serialize unless a C<TO_JSON> meth
the C<BSON_EXTJSON> environment variable is true and the
#pod C<BSON_EXTJSON_RELAXED> environment variable is false, returns a hashref
#pod compatible with
#pod MongoDB's L<extended JSON|https://githu
ob/master/source/extended-json.rst>
#pod format, which represents it as a document as follows:
#pod
#pod {"$numberLong" : "223372036854775807"}
#pod
#pod =cut
sub TO_JSON {
return int($_[0]->
t32");
}
}
#pod =method TO_JSON
#pod
#pod Returns the value as an integer.
#pod
#pod If the C<BSON_EXTJSON> environment variable is true and the
#pod C<BSON_EXTJSON_RELAXED> environment variable
rns a hashref
#pod compatible with
#pod MongoDB's L<extended JSON|https://github.com/mongodb/specifications/blob/master/source/extended-json.rst>
#pod format, which represents it as a document as foll
#pod
#pod {"$numberInt" : "42"}
#pod
#pod =cut
sub TO_JSON {
return int($_[0]->{value}) if ! $ENV{BSON_EXTJSON} || $ENV{BSON_EXTJSON_RELAXED};
return { '$numberInt' => "$_[0]->{value}" };
}
#pod =method TO_JSON
#pod
#pod Returns the value as a string.
#pod
#pod If the C<BSON_EXTJSON> option is true, it will instead
#pod be compatible with MongoDB's L<extended JSON|https://github.com/
aster/source/extended-json.rst>
#pod format, which represents it as a document as follows:
#pod
#pod {"$numberDecimal" : "2.23372036854775807E+57"}
#pod
#pod =cut
sub TO_JSON {
return "" . $_
[0]->value unless $ENV{BSON_EXTJSON};
return { '$numberDecimal' => "" . ($_[0]->value) };
}
use overload (
q{""} => sub { $_[0]->value },
fallback => 1,
);
1;
=pod
=encoding UTF-8
value} / 1.0 : 0.0;
}
#pod =method TO_JSON
#pod
#pod Returns a double.
#pod
#pod If the C<BSON_EXTJSON> environment variable is true and the
#pod C<BSON_EXTJSON_RELAXED> environment variable is false
rns a hashref
#pod compatible with
#pod MongoDB's L<extended JSON|https://github.com/mongodb/specifications/blob/master/source/extended-json.rst>
#pod format, which represents it as a document as foll
{"$numberDouble" : "42.0"}
#pod
#pod If C<BSON_EXTJSON> is false and the value is 'Inf', '-Inf' or 'NaN'
#pod (which are illegal in regular JSON), then an exception is thrown.
#pod
#pod =cut
my $u
ends 'BSON::DBRef';
sub TO_JSON {
my $self = shift;
if ( $ENV{BSON_EXTJSON} ) {
my $id = $self->id;
if (ref $id) {
$id = $id->TO_JSON;
}
else {
$id = BSON->perl_to_extjson($id);
}
my %data;
tie( %data, 'Tie::IxHash' );
$data{'$ref'} = $self->ref;
$data{'$id'} = $id;
$data{'$db'} = $s
or keys %$extra;
return \%data;
}
Carp::croak( "The value '$self' is illegal in JSON" );
}
1;
=pod
=encoding UTF-8
=head1 NAME
BSON::DBPointer - Legacy BSON type wrapper for DBP
TO_JSON
#pod
#pod If the C<BSON_EXTJSON> option is true, returns a hashref compatible with
#pod MongoDB's L<extended JSON|https://github.com/mongodb/specifications/blob/master/source/extended-json.rs
pod If the C<BSON_EXTJSON> option is false, an error is thrown, as this value
#pod can't otherwise be represented in JSON.
#pod
#pod =cut
sub TO_JSON {
if ( $ENV{BSON_EXTJSON} ) {
my %dat
regularExpression' => \%data,
};
}
Carp::croak( "The value '$_[0]' is illegal in JSON" );
}
1;
=pod
=encoding UTF-8
=head1 NAME
BSON::Regex - BSON type wrapper for regular expre
s{value} = "$args{value}";
return \%args;
}
#pod =method TO_JSON
#pod
#pod Returns value as a string.
#pod
#pod =cut
sub TO_JSON { return "$_[0]->{value}" }
use overload (
# Unary
q{bo
be stringified during construction. The default
is the empty string.
=head1 METHODS
=head2 TO_JSON
Returns value as a string.
=for Pod::Coverage BUILDARGS
=head1 OVERLOADING
The stringificatio