| 1 | package Data::SIprefixes::centi; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use bignum; | ||
| 6 | use base 'Error::Helper'; | ||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | Data::SIprefixes::centi - This provides centi matching for Data::SIprefixes. | ||
| 11 | |||
| 12 | =head1 VERSION | ||
| 13 | |||
| 14 | Version 0.0.0 | ||
| 15 | |||
| 16 | =cut | ||
| 17 | |||
| 18 | our $VERSION = '0.0.0'; | ||
| 19 | |||
| 20 | =head1 SYNOPSIS | ||
| 21 | |||
| 22 | use Data::SIprefixes::centi; | ||
| 23 | |||
| 24 | my $prefix=Data::SIprefixes::centi->new; | ||
| 25 | |||
| 26 | my $origMeasure='centimeter'; | ||
| 27 | |||
| 28 | my $measure=$prefix->longMatch( $origMeasure ); | ||
| 29 | my $long; | ||
| 30 | if ( $prefix->error ){ | ||
| 31 | warn('error:'.$prefix->error.': '.$prefix->errorString); | ||
| 32 | }elseif( ! defined( $measure ) ){ | ||
| 33 | |||
| 34 | $measure=$prefix->shortMatch( $origMeasure ); | ||
| 35 | |||
| 36 | }else{ | ||
| 37 | $long=1; | ||
| 38 | } | ||
| 39 | |||
| 40 | =head1 METHODS | ||
| 41 | |||
| 42 | =head2 new | ||
| 43 | |||
| 44 | This initiates the object. | ||
| 45 | |||
| 46 | my $prefix=$Data::SIprefixes::centi->new; | ||
| 47 | |||
| 48 | =cut | ||
| 49 | |||
| 50 | sub new { | ||
| 51 | my $string=$_[1]; | ||
| 52 | |||
| 53 | my $self={ | ||
| 54 | perror=>undef, | ||
| 55 | error=>undef, | ||
| 56 | errorString=>'', | ||
| 57 | fromBase=>0.01, | ||
| 58 | toBase=>100, | ||
| 59 | }; | ||
| 60 | bless $self; | ||
| 61 | |||
| 62 | return $self; | ||
| 63 | } | ||
| 64 | |||
| 65 | =head2 fromBase | ||
| 66 | |||
| 67 | Returns the number needed to to multiple it by to get from the unprefixed | ||
| 68 | measure to the prefixed measure. | ||
| 69 | |||
| 70 | my $fromBase=$prefix->fromBase; | ||
| 71 | |||
| 72 | =cut | ||
| 73 | |||
| 74 | sub fromBase{ | ||
| 75 | my $self=$_[0]; | ||
| 76 | |||
| 77 | if ( ! $self->errorblank ){ | ||
| 78 | $self->warnString('Failed to blank the previous error'); | ||
| 79 | } | ||
| 80 | |||
| 81 | return $self->fromBase; | ||
| 82 | } | ||
| 83 | |||
| 84 | =head2 longMatch | ||
| 85 | |||
| 86 | Matches long SI prefixed measures. | ||
| 87 | |||
| 88 | A match returns the measure with out the SI prefix, which will be '' | ||
| 89 | if no measure is specified. | ||
| 90 | |||
| 91 | my $measure=$prefix->longMatch( $origMeasure ); | ||
| 92 | if ( $prefix->error ){ | ||
| 93 | warn('error:'.$foo->error.': '.$foo->errorString); | ||
| 94 | } | ||
| 95 | |||
| 96 | =cut | ||
| 97 | |||
| 98 | sub longMatch{ | ||
| 99 | my $self=$_[0]; | ||
| 100 | my $measure=$_[1]; | ||
| 101 | |||
| 102 | if ( ! $self->errorblank ){ | ||
| 103 | $self->warnString('Failed to blank the previous error'); | ||
| 104 | } | ||
| 105 | |||
| 106 | if ( ! defined( $measure ) ){ | ||
| 107 | $self->{error}=1; | ||
| 108 | $self->{errorString}='No measure defined'; | ||
| 109 | $self->warn; | ||
| 110 | return undef; | ||
| 111 | } | ||
| 112 | |||
| 113 | if ( $measure=~/^centi/ ){ | ||
| 114 | my $origMeasure=$measure; | ||
| 115 | $measure=~s/^centi//g; | ||
| 116 | |||
| 117 | if ( $measure =~ /^ / ){ | ||
| 118 | $self->{error}=2; | ||
| 119 | $self->{errorString}='Space found after prefix, /^centi/, in "'.$origMeasure.'"' ; | ||
| 120 | $self->warn; | ||
| 121 | return undef; | ||
| 122 | } | ||
| 123 | |||
| 124 | return $measure; | ||
| 125 | } | ||
| 126 | |||
| 127 | return undef; | ||
| 128 | } | ||
| 129 | |||
| 130 | =head2 shortMatch | ||
| 131 | |||
| 132 | Matches short SI prefixed measures. | ||
| 133 | |||
| 134 | A match returns the measure with out the SI prefix, which will be '' | ||
| 135 | if no measure is specified. | ||
| 136 | |||
| 137 | my $measure=$prefix->longMatch( $origMeasure ); | ||
| 138 | if ( $prefix->error ){ | ||
| 139 | warn('error:'.$foo->error.': '.$foo->errorString); | ||
| 140 | } | ||
| 141 | |||
| 142 | =cut | ||
| 143 | |||
| 144 | sub shortMatch{ | ||
| 145 | my $self=$_[0]; | ||
| 146 | my $measure=$_[1]; | ||
| 147 | |||
| 148 | if ( ! $self->errorblank ){ | ||
| 149 | $self->warnString('Failed to blank the previous error'); | ||
| 150 | } | ||
| 151 | |||
| 152 | if ( ! defined( $measure ) ){ | ||
| 153 | $self->{error}=1; | ||
| 154 | $self->{errorString}='No measure defined'; | ||
| 155 | $self->warn; | ||
| 156 | return undef; | ||
| 157 | } | ||
| 158 | |||
| 159 | if ( $measure=~/^c/ ){ | ||
| 160 | my $origMeasure=$measure; | ||
| 161 | $measure=~s/^c//g; | ||
| 162 | |||
| 163 | if ( $measure =~ /^ / ){ | ||
| 164 | $self->{error}=2; | ||
| 165 | $self->{errorString}='Space found after prefix, /^c/, in "'.$origMeasure.'"' ; | ||
| 166 | $self->warn; | ||
| 167 | return undef; | ||
| 168 | } | ||
| 169 | |||
| 170 | return $measure; | ||
| 171 | } | ||
| 172 | |||
| 173 | return undef; | ||
| 174 | } | ||
| 175 | |||
| 176 | =head2 symbol | ||
| 177 | |||
| 178 | This returns the symbol for the prefix. | ||
| 179 | |||
| 180 | my $symbol=$prefix->symbol; | ||
| 181 | |||
| 182 | =cut | ||
| 183 | |||
| 184 | sub symbol{ | ||
| 185 | return 'c'; | ||
| 186 | } | ||
| 187 | |||
| 188 | =head2 toBase | ||
| 189 | |||
| 190 | Returns the number needed to to multiple it by to get from the prefixed measure | ||
| 191 | number to the unprefixed measure. | ||
| 192 | |||
| 193 | my $toBase=$prefix->toBase; | ||
| 194 | |||
| 195 | =cut | ||
| 196 | |||
| 197 | sub toBase{ | ||
| 198 | my $self=$_[0]; | ||
| 199 | |||
| 200 | if ( ! $self->errorblank ){ | ||
| 201 | $self->warnString('Failed to blank the previous error'); | ||
| 202 | } | ||
| 203 | |||
| 204 | return $self->toBase; | ||
| 205 | } | ||
| 206 | |||
| 207 | =head1 ERROR CODES | ||
| 208 | |||
| 209 | =head2 1 | ||
| 210 | |||
| 211 | Nothing passed for a measure. | ||
| 212 | |||
| 213 | =head2 2 | ||
| 214 | |||
| 215 | Space found after prefix. | ||
| 216 | |||
| 217 | =head1 AUTHOR | ||
| 218 | |||
| 219 | Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >> | ||
| 220 | |||
| 221 | =head1 BUGS | ||
| 222 | |||
| 223 | Please report any bugs or feature requests to C<bug-data-siprefixes at rt.cpan.org>, or through | ||
| 224 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-SIprefixes>. I will be notified, and then you'll | ||
| 225 | automatically be notified of progress on your bug as I make changes. | ||
| 226 | |||
| 227 | |||
| 228 | |||
| 229 | |||
| 230 | =head1 SUPPORT | ||
| 231 | |||
| 232 | You can find documentation for this module with the perldoc command. | ||
| 233 | |||
| 234 | perldoc Data::SIprefixes::centi | ||
| 235 | |||
| 236 | |||
| 237 | You can also look for information at: | ||
| 238 | |||
| 239 | =over 4 | ||
| 240 | |||
| 241 | =item * RT: CPAN's request tracker (report bugs here) | ||
| 242 | |||
| 243 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-SIprefixes> | ||
| 244 | |||
| 245 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 246 | |||
| 247 | L<http://annocpan.org/dist/Data-SIprefixes> | ||
| 248 | |||
| 249 | =item * CPAN Ratings | ||
| 250 | |||
| 251 | L<http://cpanratings.perl.org/d/Data-SIprefixes> | ||
| 252 | |||
| 253 | =item * Search CPAN | ||
| 254 | |||
| 255 | L<http://search.cpan.org/dist/Data-SIprefixes/> | ||
| 256 | |||
| 257 | =back | ||
| 258 | |||
| 259 | |||
| 260 | =head1 ACKNOWLEDGEMENTS | ||
| 261 | |||
| 262 | |||
| 263 | =head1 LICENSE AND COPYRIGHT | ||
| 264 | |||
| 265 | Copyright 2012 Zane C. Bowers-Hadley. | ||
| 266 | |||
| 267 | This program is free software; you can redistribute it and/or modify it | ||
| 268 | under the terms of either: the GNU General Public License as published | ||
| 269 | by the Free Software Foundation; or the Artistic License. | ||
| 270 | |||
| 271 | See http://dev.perl.org/licenses/ for more information. | ||
| 272 | |||
| 273 | |||
| 274 | =cut | ||
| 275 | |||
| 276 | 1; # End of Data::SIprefixes::centi |