BSON::Code(3pm)
π BSON::Code π
okay bestie, welcome to BSON::Code, a lil page from the User Contributed Perl Documentation collection. this one is a BSON type wrapper for Javascript code β yes, the actual Javascript, chillin' inside your BSON. no cap.
β¨ NAME β¨
BSON::Code β a BSON type wrapper for Javascript code. that's the whole vibe. π
πΈ VERSION πΈ
version v1.12.2 β she's serving, she's current, she's iconic.
π¦ SYNOPSIS π¦
here's the tea, fr fr:
use BSON::Types ':all';
$code = bson_code( $javascript );
$code = bson_code( $javascript, $scope );
two whole ways to build her. pick your fighter. π
π DESCRIPTION π
so what is this module? it hands you a BSON type wrapper for the "Javascript code" type, and also for the "Javascript with Scope" BSON types. that's it. that's the job. she's lowkey just a fancy lil container and she's thriving. π«Ά
π ATTRIBUTES π
π code
a string holding Javascript code. defaults to the empty string β so if you don't pass anything, she's just vibing there, empty, waiting for you. no thoughts, head empty. π
π scope
an optional hash reference containing variables in the scope of code. defaults to undef. so like, the lil friend group that code runs around with. if you don't give her one, she flies solo. βοΈ
β METHODS β
π length
returns the length of the code attribute. that's it. she's measuring. she's slaying. she's got a tape measure and she's not afraid to use it. πβ¨
π TO_JSON
okay so this one's got a condition, listen up. π
if the BSON_EXTJSON option is true, this returns a hashref compatible with MongoDB's extended JSON format, which represents it as a document as follows:
{"$code" : "<code>"}
{"$code" : "<code>", "$scope" : { ... } }
(the extended JSON spec lives over at <https://github.com/mongodb/specifications/blob/master/source/extended-json.rst> if you wanna read the source material, iykyk)
but if the BSON_EXTJSON option is false? bestie. an error is thrown, because this value literally can't be represented in JSON any other way. it's giving "no representation, no service." don't fight it. π
π AUTHORS π
the legends who made this happen:
- David Golden
<david@mongodb.com> - Stefan G.
<minimalist@lavabit.com>
absolute icons, both of them. π«‘
πΈ COPYRIGHT AND LICENSE πΈ
This software is Copyright (c) 2020 by Stefan G. and MongoDB, Inc.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
and that's the whole page, bestie! π this lil doc was brought to you by perl v5.30.3, dated 2020-08-14, and it's the BSON::Code(3pm) manpage, signing off. go forth and wrap your Javascript. periodt. π
β¨
π¦ where this page comes from
- debian bookworm: libbson-perl 1.12.2-1 Β· Apache-2.0
- ubuntu jammy: libbson-perl 1.12.2-1 Β· Apache-2.0
- ubuntu noble: libbson-perl 1.12.2-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms