Class::Measure(3pm)

πŸ“¦
version 0.10 Β· 6 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ‘‘ Class::Measure β€” the manual page, but make it a vibe ✨

okay bestie, welcome to Class::Measure β€” this is the perl manpage for it, page Class::Measure(3pm) if you're being formal (you're not, and that's fine). Sit down, grab a strawberry πŸ“, and let's talk units of measurement, because this module is genuinely iconic and I need you to know it.


✨ NAME ✨

Class::Measure β€” create, compare, and convert units of measurement. fr fr that's the whole job description πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

lowkey there's not much here β€” go peep Class::Measure::Length for some examples, that's where the real content lives:

See Class::Measure::Length for some examples.

🌈 DESCRIPTION 🌈

So here's the tea, bestie: this is a base class that gets inherited by all the Class::Measure classes. Out of the box, this distribution ships with exactly one of those classes: Class::Measure::Length. πŸŽ€

And the planned girlies, coming soon (no timeline given, don't @ me):

  • Class::Measure::Area
  • Class::Measure::Mass
  • Class::Measure::Space
  • Class::Measure::Temperature
  • Class::Measure::Volume

Every single method described below is available in all Class::Measure classes β€” so once you learn them here, you're set for the whole friend group. 🫢


πŸ’… METHODS πŸ’…

🌸 new 🌸

my $m = new Class::Measure::Length( 1, 'inch' );

Creates a brand new measurement object. You must pass an initial measurement and a default unit β€” it's giving "no defaults, bring your own numbers." ✨

In most cases though, the measurement class you're using will export a lil helper method so you don't have to do this by hand. Like, Class::Measure::Length exports the length() method. So cute of it.

🧚 unit 🧚

my $unit = $m->unit();

Returns the object's default unit. That's it. That's the whole method. Short queen. πŸ‘‘

πŸ’– set_unit πŸ’–

$m->set_unit( 'feet' );

Sets the default unit of the measurement. New default, who dis.

🌟 value 🌟

my $yards = $m->value('yards');
my $val = $m->value();
print "$m is the same as $val when in a string\n";

Retrieves the value of the measurement in the default unit. You can also pass a unit, in which case the value gets converted to that unit and returned β€” like a lil glow-up on the way out. πŸ’«

also not me needing you to know: this method is what handles the overloading for stringifying the object. so when you interpolate $m into a string, this is the girl doing the work behind the scenes. main character energy, honestly.

⭐ set_value ⭐

my $m = length( 0, 'inches' );
$m->set_value( 12 ); # 12 inches.
$m->set_value( 1, 'foot' ); # 1 foot.

Sets the measurement in the default unit. You can also specify a new default unit at the same time if you're feeling spicy. 🌢️

πŸŽ€ reg_units πŸŽ€

Class::Measure::Length->reg_units(
    'inch', 'foot', 'yard',
);

Registers one or more units for use in the specified class. Bestie, register them in the singular, most common form β€” that's the rule, don't fight it. πŸ™ˆ

πŸ¦‹ units πŸ¦‹

my @units = Class::Measure::Length->units();

Returns a list of all registered units. It's giving roster reveal. πŸ“‹βœ¨

πŸ’œ reg_aliases πŸ’œ

Class::Measure::Length->reg_aliases(
    ['feet','ft'] => 'foot',
    ['in','inches'] => 'inch',
    'yards' => 'yard'
);

Register alternate names for units β€” nicknames, if you will. πŸ₯°

It expects two arguments per unit you're aliasing:

  • the first argument is the alias (a scalar) or aliases (an array ref)
  • the second argument is the unit you're aliasing them to

πŸ”₯ reg_convs πŸ”₯

Class::Measure::Length->reg_convs(
    12, 'inches' => 'foot',
    'yard' => '3', 'feet'
);

Registers a unit conversion. There are three distinct ways to specify a new conversion, and each one needs three arguments. Let's go through them one by one, bestie, because this is the part where people get lost and I refuse to let that be you. 😀

$count1, $unit1 => $unit2
$unit1 => $count2, $unit2

These first two syntaxes create automatic reverse conversions as well. So if you say there are 12 inches in a foot, it implies there are 1/12 feet in an inch. Math is doing its lil flip and honestly? Slay. πŸ”„

$unit1 => $unit2, $sub

The third syntax accepts a subroutine as the last argument. The subroutine gets called with the value of $unit1, and its return value gets assigned to $unit2.

⚠️ heads up bestie: this third syntax does not create a reverse conversion automatically. You gotta handle that yourself. No cap.

🫢 SUPPORT 🫢

Got bugs? Got feature requests? Please submit them to the Class-Measure GitHub issue tracker:

<https://github.com/bluefeet/Class-Measure/issues>

Go off, they're listening. πŸ’Œ


πŸ‘‘ AUTHOR πŸ‘‘

Aran Clary Deltac <bluefeet@gmail.com>

🌸 CONTRIBUTORS 🌸

Roland van Ipenburg <roland@rolandvanipenburg.com>

πŸ“œ LICENSE πŸ“œ

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Periodt. πŸ’–


and that's the whole page, bestie β€” you ate that. πŸŽ€ this was Class::Measure(3pm), User Contributed Perl Documentation, from perl v5.36.0, dated 2023-10-01. mwah, go convert some units. πŸ’…βœ¨

πŸ“¦ where this page comes from