NAME

Data::SIprefixes - This helps with working with numbers with SI prefixed measures.

VERSION

Version 0.0.1

SYNOPSIS

use Data::SIprefixes;

my $sim=Data::SIprefixes->new('3 grams');

print 'Number: '.$sip->numberGet.
    "\nprefix: ".$sip->prefixGet.
    "\nmeasure: ".$sip->measureGet.
    "\nsymbol: ".$sip->symbolGet.
    "\nuse symbol: ".$sip->symbolUse.
    "\nstring: ".$sip->string."\n";

While new can properly parse some prefix/measure combos, the ones below are set statically as they can cause confusion.

amp
ampere
coulomb
farad
Gy
henry
kat
katal
kelvin
m
metre
meter
mol
mole
newton
Pa
pascal
T

Because of this, while it is possible of matching other symbols with out a measure, the ones listed below can't be.

m
T

METHODS

new

This initiates the object.

One argument is required and that is the string.

my $sip->new('3 kilometer');
if ( $sip->error ){
    warn('error:'.$sip->error.': '.$sip->errorString);
}

measureGet

This returns the measure part.

This won't error as long as new did not.

If no measure was found, '' is returned.

my $measure=$sip->measureSet('gram');

measureSet

This returns the measure part.

This sets the measure. This will accept '' as a valid measure.

$sip->measureSet( $measure );
if ( $sip->error ){
    warn('error:'.$sip->error.': '.$sip->errorString);
}

numberGet

This returns the numeric part.

This won't error as long as new did not.

my $error=$sip->numberGet;

numberSet

This sets the numeric part.

This won't error as long as what you provide a number.

my $error=$sip->numberGet('4');

prefixGet

This returns the current metric prefix.

As long as it new worked with out error, then this will not error.

A return of '', means there is no current prefix.

my $prefix=$sip->prefixGet;

prefixSet

This sets the metric prefix and update the number to reflect that change.

One argument is accepted and it is the new prefix. A value of '' set it to no prefix.

If no prefix is specified, '' is used.

$sip->prefixSet('kilo');

string

This returns a formatted string of the number, prefix/symbol, and measure.

This will not error as long as the module initialized with out error.

my $string=$sip->string;

symbolGet

This returns the symbol for the prefix.

As long as it new worked with out error, then this will not error.

A return of '', means there is no current prefix and thus no symbol.

my $symbol=$sip->getSymbol;

symbolUse

Returns if the symbol should be used or not.

The returned value is boolean and this is based off of how it is matched.

This will not error as long as the module has initialized with out error.

my $symbolUse=$sim->symbolUse;

ERROR CODES

1

Failed to load one of the prefixes.

2

The string does not begin with a number.

3

No number specified.

4

No recognized prefix specified.

5

No measure specified.

AUTHOR

Zane C. Bowers-Hadley, <vvelox at vvelox.net>

BUGS

Please report any bugs or feature requests to bug-data-siprefixes at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-SIprefixes. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Data::SIprefixes

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2012 Zane C. Bowers-Hadley.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.