Mango:...:Number(3pm)

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

✨ Mango:...:Number ✨

okay bestie, so this is Mango::BSON::Number from the User Contributed Perl Documentation β€” it's a little container that holds a number and a strict type, no vibes-based guessing allowed πŸ’…


🌸 NAME 🌸

Mango::BSON::Number β€” numerical types, but make it typed πŸ¦‹


✨ SYNOPSIS ✨

use Mango::BSON;
use Mango::BSON::Number;

my $number = Mango::BSON::Number->new(666, Mango::BSON::INT64);
say $number;

like. that's it. that's the whole vibe. πŸ‘‘


πŸ’– DESCRIPTION πŸ’–

Mango::BSON::Number is literally just a container for numerical values, except it comes with a strict type attached. no chaos, no "is this an int or a float" existential crisis at 3am. it knows. ✨


πŸŽ€ METHODS πŸŽ€

Mango::BSON::Number inherits all methods from Mojo::Base and implements the following new ones, bestie 🫢

πŸ¦‹ new

my $number = Mango::BSON::Number->new(3.14, Mango::BSON::DOUBLE);

constructs a brand new Mango::BSON::Number object for you, iconique πŸ’…

⚠️ it will croak if the value you give it is incompatible with the type you asked for. so don't try it. it's giving consequences.

the 3 supported types are DOUBLE, INT32 and INT64. only those three. periodt. βœ‹

🌈 TO_JSON

my $num = $obj->TO_JSON;

returns the numerical value. that's the whole job, and it ate. πŸ”₯

🌸 to_string

my $str = $num->to_string;

returns the value as a string. string-ified. slayed. ✨

πŸ’œ isa_number

my $flags = Mango::BSON::Number::isa_number(25);

determines whether the variable you handed over is a number by peeking at the internal flags of the perl scalar object πŸ‘€ (yes, we're looking at its insides, no cap).

returns undef if the value is not a number, or a non-null value otherwise. and that returned value contains flags you can use for a finer analysis of the scalar β€” iykyk 🧚

⭐ guess_type

my $mongo_type = Mango::BSON::Number::guess_type(25);

picks which BSON type to use when encoding the numeric value you gave it. the possible types are Mango::BSON::DOUBLE, Mango::BSON::INT32 or Mango::BSON::INT64 πŸ’«

returns undef if the value you passed isn't a number. no number, no type, no drama. πŸ™ˆ


πŸ’… OPERATORS πŸ’…

Mango::BSON::Time overloads the following operators (yes it says Time, that's what the original says, we don't ask questions, we just report the facts 🫑).

πŸŽ€ bool

my $bool = !!$num;

🌸 stringify

my $str = "$num";

alias for to_string β€” same energy, different outfit πŸ’–


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, bestie 🫢 this iconic little number was brought to you by perl v5.30.3, dated 2020-06-05 β€” Mango:...:Number(3pm), no cap, fr fr πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’