Mango:...bjectID(3pm)

πŸ“¦
version 1.30 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Mango::BSON::ObjectID β€” Object ID type πŸ’–

okay bestie, so this is Mango::BSON::ObjectID, straight out of the User Contributed Perl Documentation collection (3pm section, iykyk). It's the lil container for the BSON object id type that Mango::BSON uses. That's the whole vibe. Let's get into it. πŸ¦‹


✨ SYNOPSIS ✨

use Mango::BSON::ObjectID;

my $oid = Mango::BSON::ObjectID->new('1a2b3c4e5f60718293a4b5c6');
say $oid->to_epoch;

literally that's it, that's the whole flex. πŸ’…


🌸 DESCRIPTION 🌸

Mango::BSON::ObjectID is a container for the BSON object id type used by Mango::BSON. no cap, that's the entire job description, and it does it beautifully. πŸ‘‘


πŸŽ€ METHODS πŸŽ€

Mango::BSON::ObjectID inherits all methods from Mojo::Base (yes, it's got family money πŸ’…) and implements the following new ones.

from_epoch

my $oid = $oid->from_epoch(1359840145);

Generate a new object id with a specific epoch time. you hand it a timestamp, it hands you a fresh oid. iconic. ✨

new

my $oid = Mango::BSON::ObjectID->new;
my $oid = Mango::BSON::ObjectID->new('1a2b3c4e5f60718293a4b5c6');

Construct a brand new Mango::BSON::ObjectID object. call it with nothing and it does its own thing, or pass it a string and it uses that. main character energy either way. 🌈

to_bytes

my $bytes = $oid->to_bytes;

Gives you the object id in binary form. spooky little byte blob, but make it useful. πŸ”₯

to_epoch

my $epoch = $oid->to_epoch;

Extract the epoch seconds from the object id. time travel but make it one function call. ⭐

to_string

my $str = $oid->to_string;

Stringify the object id. that's the one you want when you need it to look normal. πŸ’œ


πŸ‘‘ OPERATORS πŸ‘‘

Mango::BSON::ObjectID overloads the following operators, so it can do cute tricks when you use it like a regular Perl value.

bool

my $bool = !!$oid;

Always true. always. it's giving unshakeable confidence, and honestly? we love that for it. πŸ’–

stringify

my $str = "$oid";

Alias for to_string. same energy, shorter syntax. πŸŽ€


πŸ” SEE ALSO πŸ”


and that's the whole page, bestie!! 🫢 this gorgeous lil doc is perl v5.30.3, dated 2020-06-05, and it lives in the Mango:...bjectID(3pm) section of the User Contributed Perl Documentation. go forth and slay your object ids. πŸ’…βœ¨πŸŒΈ