Class::Measure(3pm)
π 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::AreaClass::Measure::MassClass::Measure::SpaceClass::Measure::TemperatureClass::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
- debian trixie: libclass-measure-perl 0.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libclass-measure-perl 0.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libclass-measure-perl 0.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libclass-measure-perl 0.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms