1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
# NAME
Class::Measure - Create, compare, and convert units of measurement.
# SYNOPSIS
See [Class::Measure::Length](https://metacpan.org/pod/Class%3A%3AMeasure%3A%3ALength) for some examples.
# DESCRIPTION
This is a base class that is inherited by the Class::Measure
classes. This distribution comes with the class [Class::Measure::Length](https://metacpan.org/pod/Class%3A%3AMeasure%3A%3ALength).
The classes [Class::Measure::Area](https://metacpan.org/pod/Class%3A%3AMeasure%3A%3AArea), [Class::Measure::Mass](https://metacpan.org/pod/Class%3A%3AMeasure%3A%3AMass),
[Class::Measure::Space](https://metacpan.org/pod/Class%3A%3AMeasure%3A%3ASpace), [Class::Measure::Temperature](https://metacpan.org/pod/Class%3A%3AMeasure%3A%3ATemperature),
and [Class::Measure::Volume](https://metacpan.org/pod/Class%3A%3AMeasure%3A%3AVolume) are planned and will be added soon.
The methods described here are available in all Class::Measure classes.
# METHODS
## new
```perl
my $m = new Class::Measure::Length( 1, 'inch' );
```
Creates a new measurement object. You must pass an initial
measurement and default unit.
In most cases the measurement class that you are using
will export a method to create new measurements. For
example [Class::Measure::Length](https://metacpan.org/pod/Class%3A%3AMeasure%3A%3ALength) exports the
`length()` method.
## unit
```perl
my $unit = $m->unit();
```
Returns the object's default unit.
## set\_unit
```
$m->set_unit( 'feet' );
```
Sets the default unit of the measurement.
## value
```perl
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 may specify a unit in which
case the value is converted to the unit and returned.
This method is also used to handle overloading of
stringifying the object.
## set\_value
```perl
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 may
specify a new default unit as well.
## reg\_units
```
Class::Measure::Length->reg_units(
'inch', 'foot', 'yard',
);
```
Registers one or more units for use in the specified
class. Units should be in the singular, most common,
form.
## units
```perl
my @units = Class::Measure::Length->units();
```
Returns a list of all registered units.
## reg\_aliases
```perl
Class::Measure::Length->reg_aliases(
['feet','ft'] => 'foot',
['in','inches'] => 'inch',
'yards' => 'yard'
);
```
Register alternate names for units. Expects two
arguments per unit to alias. The first argument
being the alias (scalar) or aliases (array ref), and
the second argument being the unit to alias them to.
## reg\_convs
```perl
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. Each requires three
arguments.
```perl
$count1, $unit1 => $unit2
$unit1 => $count2, $unit2
```
These first two syntaxes create automatic reverse conversions
as well. So, saying there are 12 inches in a foot implies
that there are 1/12 feet in an inch.
```perl
$unit1 => $unit2, $sub
```
The third syntax accepts a subroutine as the last argument
the subroutine will be called with the value of $unit1 and
it's return value will be assigned to $unit2. This
third syntax does not create a reverse conversion automatically.
# SUPPORT
Please submit bugs and feature requests to the
Class-Measure GitHub issue tracker:
[https://github.com/bluefeet/Class-Measure/issues](https://github.com/bluefeet/Class-Measure/issues)
# 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.
|