| 1 | package Class::Measure::Length; | ||
| 2 | 1 | ▶ | use 5.008001; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | our $VERSION = '0.08'; | |
| 6 | |||
| 7 | =encoding utf8 | ||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | Class::Measure::Length - Calculate measurements of length. | ||
| 12 | |||
| 13 | =head1 SYNOPSIS | ||
| 14 | |||
| 15 | use Class::Measure::Length; | ||
| 16 | |||
| 17 | print length( 2, 'km' )->meters(); | ||
| 18 | |||
| 19 | =cut | ||
| 20 | |||
| 21 | 1 | ▶ | use base qw( Class::Measure ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | |||
| 23 | 1 | use Sub::Exporter -setup => { | |
| 24 | exports => [qw( length )] | ||
| 25 | 1 | ▶ | }; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 26 | |||
| 27 | =head1 METHODS | ||
| 28 | |||
| 29 | This module inherits all the methods made available by | ||
| 30 | L<Class::Measure>. | ||
| 31 | |||
| 32 | =head2 length | ||
| 33 | |||
| 34 | $m = length( 2, 'metres' ); | ||
| 35 | |||
| 36 | Creates a new measurement object. | ||
| 37 | |||
| 38 | =cut | ||
| 39 | |||
| 40 | 2 | ▶ | sub length { return __PACKAGE__->new(@_); } |
|
Subroutine
length: called CC=1 SCAR=0.0
Pod
documented
| |||
| 41 | |||
| 42 | =head1 UNITS | ||
| 43 | |||
| 44 | =head2 International System of Units | ||
| 45 | |||
| 46 | Also known as SI and "metric", this unit of measure | ||
| 47 | includes the following. | ||
| 48 | |||
| 49 | kilometre | ||
| 50 | metre | ||
| 51 | centimetre | ||
| 52 | millimetre | ||
| 53 | decimetre | ||
| 54 | micrometre | ||
| 55 | nanometre | ||
| 56 | |||
| 57 | And all veriations are aliased, such as "m", "meter", | ||
| 58 | "meters", "metres". | ||
| 59 | |||
| 60 | =cut | ||
| 61 | |||
| 62 | 1 | __PACKAGE__->reg_units( | |
| 63 | qw( kilometre centimetre millimetre decimetre micrometre nanometre metre ) | ||
| 64 | ); | ||
| 65 | 1 | __PACKAGE__->reg_aliases( | |
| 66 | ['kilometer','km','kilometers','kilometres','klick','klicks'] => 'kilometre', | ||
| 67 | ['meter','m','meters','metres'] => 'metre', | ||
| 68 | ['centimeter','cm','centimeters','centimetres'] => 'centimetre', | ||
| 69 | ['millimeter','mm','millimeters','millimetres'] => 'millimetre', | ||
| 70 | ['decimeter','decimeters','decimetres'] => 'decimetre', | ||
| 71 | ['micrometer','micrometers','micron','microns','micrometres'] => 'micrometre', | ||
| 72 | ['nanometer','nanometers','nanometres'] => 'nanometre', | ||
| 73 | ); | ||
| 74 | 1 | __PACKAGE__->reg_convs( | |
| 75 | 'km' => 1000, 'm', | ||
| 76 | 100, 'cm' => 'm', | ||
| 77 | 10, 'mm' => 'cm', | ||
| 78 | 'decimetre' => 10, 'cm', | ||
| 79 | 1000, 'microns' => 'mm', | ||
| 80 | 1000, 'nanometers' => 'micron', | ||
| 81 | ); | ||
| 82 | |||
| 83 | =head2 Shared | ||
| 84 | |||
| 85 | These units are shared by with the US and Imperial | ||
| 86 | unit systems. | ||
| 87 | |||
| 88 | inch | ||
| 89 | foot | ||
| 90 | yard | ||
| 91 | rod | ||
| 92 | mile | ||
| 93 | chain | ||
| 94 | furlong | ||
| 95 | |||
| 96 | All relevant aliases included. | ||
| 97 | |||
| 98 | =cut | ||
| 99 | |||
| 100 | 1 | __PACKAGE__->reg_units( | |
| 101 | qw( inch foot yard rod mile chain furlong ) | ||
| 102 | ); | ||
| 103 | 1 | __PACKAGE__->reg_aliases( | |
| 104 | ['in','inches'] => 'inch', | ||
| 105 | ['feet','ft'] => 'foot', | ||
| 106 | 'yards' => 'yard', | ||
| 107 | ['pole','poles','perch','perches','rods'] => 'rod', | ||
| 108 | 'miles' => 'mile', | ||
| 109 | 'chains' => 'chain', | ||
| 110 | 'furlongs' => 'furlong', | ||
| 111 | ); | ||
| 112 | 1 | __PACKAGE__->reg_convs( | |
| 113 | 'inch' => 25.4, 'mm', | ||
| 114 | 'foot' => 12, 'inches', | ||
| 115 | 'yard' => 3, 'feet', | ||
| 116 | 'yard' => 91.44, 'cm', | ||
| 117 | 'rod' => 16.5, 'feet', | ||
| 118 | 'mile' => 1.609344, 'km', | ||
| 119 | 'mile' => 5280, 'feet', | ||
| 120 | 'chain' => 66, 'feet', | ||
| 121 | 'furlong' => 10, 'chains', | ||
| 122 | ); | ||
| 123 | |||
| 124 | =head2 United Stats | ||
| 125 | |||
| 126 | Units specific to the United States. | ||
| 127 | |||
| 128 | survey_mile | ||
| 129 | link | ||
| 130 | fathom | ||
| 131 | cable_length | ||
| 132 | |||
| 133 | Aliases included. | ||
| 134 | |||
| 135 | =cut | ||
| 136 | |||
| 137 | 1 | __PACKAGE__->reg_units( | |
| 138 | qw( survey_mile link fathom cable_length ) | ||
| 139 | ); | ||
| 140 | 1 | __PACKAGE__->reg_aliases( | |
| 141 | 'survey_miles' => 'survey_mile', | ||
| 142 | 'links' => 'link', | ||
| 143 | 'fathoms' => 'fathom', | ||
| 144 | 'cable_lengths' => 'cable_length', | ||
| 145 | ); | ||
| 146 | 1 | __PACKAGE__->reg_convs( | |
| 147 | 'survey_mile' => 8, 'furlongs', | ||
| 148 | 'link' => 0.001, 'furlongs', | ||
| 149 | 'fathom' => 6, 'feet', | ||
| 150 | 'cable_length' => 123, 'fathoms', | ||
| 151 | ); | ||
| 152 | |||
| 153 | =head2 Imperial | ||
| 154 | |||
| 155 | Imperial (english) units. The only unit included | ||
| 156 | in this set is "league". | ||
| 157 | |||
| 158 | =cut | ||
| 159 | |||
| 160 | 1 | __PACKAGE__->reg_units( | |
| 161 | qw( league ) | ||
| 162 | ); | ||
| 163 | 1 | __PACKAGE__->reg_aliases( | |
| 164 | 'leagues' => 'league', | ||
| 165 | ); | ||
| 166 | 1 | __PACKAGE__->reg_convs( | |
| 167 | 'league' => 3, 'miles', | ||
| 168 | ); | ||
| 169 | |||
| 170 | =head2 Other | ||
| 171 | |||
| 172 | light_second | ||
| 173 | nautical_mile | ||
| 174 | |||
| 175 | =cut | ||
| 176 | |||
| 177 | 1 | __PACKAGE__->reg_units( | |
| 178 | qw( light_second nautical_mile ) | ||
| 179 | ); | ||
| 180 | 1 | __PACKAGE__->reg_aliases( | |
| 181 | 'light_seconds' => 'light_second', | ||
| 182 | 'nautical_miles' => 'nautical_mile', | ||
| 183 | ); | ||
| 184 | 1 | __PACKAGE__->reg_convs( | |
| 185 | 'light_second' => 299792458, 'm', | ||
| 186 | 'nautical_mile' => 1852, 'm', | ||
| 187 | ); | ||
| 188 | |||
| 189 | 1 | 1; | |
| 190 | __END__ | ||