BSON::Code(3pm)

πŸ“¦
version 1.12.2 Β· 5 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

πŸ’– 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. 🫑


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