Compare commits

...

4 Commits

Author SHA1 Message Date
Zane C. B-H a6f8ebc480 rename for git
git-svn-id: svn://127.0.0.1/Perl/Data-SImeasures/tags/0.0.0@992 0c1c3402-1be1-de11-8092-0022686faf23
2018-08-27 05:59:14 +00:00
Zane C. B-H 2a9ff37345 note the changes in the directory body
git-svn-id: svn://127.0.0.1/Perl/Data::SImeasures/tags/0.0.0@790 0c1c3402-1be1-de11-8092-0022686faf23
2012-05-19 21:13:01 +00:00
Zane C. B-H b5a8ebd365 note the changes
git-svn-id: svn://127.0.0.1/Perl/Data::SImeasures/tags/0.0.0@789 0c1c3402-1be1-de11-8092-0022686faf23
2012-05-19 21:11:27 +00:00
Zane C. B-H 95c16051bd tag 0.0.0
git-svn-id: svn://127.0.0.1/Perl/Data::SImeasures/tags/0.0.0@784 0c1c3402-1be1-de11-8092-0022686faf23
2012-05-19 14:30:30 +00:00
7 changed files with 281 additions and 32 deletions

1
.toader/autodoc/dirs Normal file
View File

@ -0,0 +1 @@
Data-SImeasures/

9
.toader/index Normal file
View File

@ -0,0 +1,9 @@
renderer: html
summary:
Date: Sat, 19 May 2012 16:11:46 -0500
MIME-Version: 1.0
<pre>
0.0.0 2012-05-19/16:10
-Initial release.
</pre>

View File

@ -1,5 +1,6 @@
Revision history for Data-SImeasures
0.01 Date/time
First version, released on an unsuspecting world.
0.0.0 2012-05-19/16:10
-Initial release.

View File

@ -9,12 +9,13 @@ WriteMakefile(
VERSION_FROM => 'lib/Data/SImeasures.pm',
ABSTRACT_FROM => 'lib/Data/SImeasures.pm',
($ExtUtils::MakeMaker::VERSION >= 6.3002
? ('LICENSE'=> 'perl')
: ()),
? ('LICENSE'=> 'perl')
: ()),
PL_FILES => {},
PREREQ_PM => {
'Test::More' => 0,
'Error::Helper' => 0,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Data-SImeasures-*' },
);
);

View File

@ -1,16 +1,7 @@
Data-SImeasures
The README is used to introduce the module and provide instructions on
how to install the module, any machine dependencies it may have (for
example C compilers and installed libraries) and any other information
that should be provided before the module is installed.
A README file is required for CPAN modules since CPAN extracts the README
file from a module distribution so that people browsing the archive
can use it to get an idea of the module's uses. It is usually a good idea
to provide version information here so that people can decide whether
fixes for the module are worth downloading.
This helps helps with checking if a measure is a SI
supported one or not.
INSTALLATION

1
Data-SImeasures/TODO Normal file
View File

@ -0,0 +1 @@
-Implement symbol checking for ohm and Celsius.

View File

@ -3,52 +3,297 @@ package Data::SImeasures;
use 5.006;
use strict;
use warnings;
use base 'Error::Helper';
=head1 NAME
Data::SImeasures - The great new Data::SImeasures!
Data::SImeasures - The checks if something is a SI measure or not.
=head1 VERSION
Version 0.01
Version 0.0.0
=cut
our $VERSION = '0.01';
our $VERSION = '0.0.0';
=head1 SYNOPSIS
Quick summary of what the module does.
Perhaps a little code snippet.
use Data::SImeasures;
my $foo = Data::SImeasures->new();
my $sim = Data::SImeasures->new;
...
=head1 EXPORT
It is worth noting that some measures are present more than
once as that is more than one common form. These are listed
below.
A list of functions that can be exported. You can delete this section
if you don't export anything, such as for a purely object-oriented module.
amp
ampere
=head1 SUBROUTINES/METHODS
meter
metre
=head2 function1
Celsius
degree Celsius
This module does have issues dealing with ohm and Celsius as
when it comes to the symbol as depending on the source, it
may be represented differently. This will be fixed eventually.
=head1 METHODS
=head2 new
This initilizes the object.
my $sim=Data::SImeasures->new;
=cut
sub function1 {
sub new{
my $self={
perror=>undef,
error=>undef,
errorString=>'',
};
bless $self;
$self->{measures}={
'amp'=>'A',
'ampere'=>'A',
'metre'=>'m',
'meter'=>'m',
'gram'=>'g',
'second'=>'s',
'kelvin'=>'K',
'mole'=>'mol',
'candela'=>'cd',
'hertz'=>'Hz',
'radian'=>'rad',
'steradian'=>'sr',
'newton'=>'N',
'pascal'=>'Pa',
'joule'=>'J',
'watt'=>'W',
'coulomb'=>'C',
'volt'=>'V',
'farad'=>'F',
'ohm'=>'ERROR',
'siemens'=>'S',
'weber'=>'Wb',
'tesla'=>'T',
'henry'=>'H',
'degree Celsius'=>'ERROR',
'Celsius'=>'ERROR',
'lumen'=>'lm',
'lux'=>'lx',
'becquere'=>'Bq',
'gray'=>'Gy',
'sievert'=>'Sv',
'katal'=>'kat',
};
return $self;
}
=head2 function2
=head2 getSymbol
This returns the symbol for the specified measure.
If if it ohm or Celsius, undef is returned.
my $symbol=$self->getSymbol( $symbol );
if ( $sim->error ){
warn('Failed to match the specified measure');
}else{
if ( ! defined( $symbol ) ){
warn( $measure.' is does not have a supported symbol' );
}else{
print "The symbol for ".$measure." is ".$symbol."\n";
}
}
=cut
sub function2 {
sub getSymbol{
my $self=$_[0];
my $measure=$_[1];
if ( ! $self->errorblank ){
$self->warnString('Failed to blank the previous error');
}
if ( ! defined( $measure ) ){
$self->{error}=1;
$self->{errorString}='No measure specified';
$self->warn;
return undef;
}
if ( ! $self->match( $measure ) ){
$self->{error}=2;
$self->{errorString}='';
$self->warn;
return undef;
}
my $symbol=$self->{measures}{$measure};
if ( $symbol eq 'ERROR' ){
return undef;
}
return $symbol;
}
=head2 match
This matches measures.
This only matches the name, not the symbol.
If ends in an s, plural, and does not match
siemens or Celsius, the end s is removed.
'1' is returned on it being matched and '0'
if it is not.
As long as an measure is defined, it wont error.
if ( $sim->match( $measure ) ){
print "It is a valid measure.\n";
}
=cut
sub match{
my $self=$_[0];
my $measure=$_[1];
if ( ! $self->errorblank ){
$self->warnString('Failed to blank the previous error');
}
if ( ! defined( $measure ) ){
$self->{error}=1;
$self->{errorString}='No measure specified';
$self->warn;
return undef;
}
#remove the end S if it is plural
if (
( $measure=~/s$/ ) &&
( $measure!~/siemens$/ ) &&
( $measure!~/Celsius$/ )
){
$measure=~s/s$//;
}
if ( defined( $self->{measures}{$measure} ) ){
return 1;
}
return 0;
}
=head2 matchAll
This matches either the symbol or the name of the measure.
if ( $sim->matchAll( $measure ) ){
print "It is a valid measure.\n";
}
=cut
sub matchAll{
my $self=$_[0];
my $measure=$_[1];
if ( ! $self->errorblank ){
$self->warnString('Failed to blank the previous error');
}
if ( ! defined( $measure ) ){
$self->{error}=1;
$self->{errorString}='No symbol specified';
$self->warn;
return undef;
}
if ( $self->match( $measure ) ){
return 1;
}
if ( $self->matchSymbol( $measure ) ){
return 1;
}
return undef;
}
=head2 matchSymbol
This matches measure symbols.
'1' is returned on it being matched and '0'
if it is not.
As long as an measure is defined, it wont error.
This currently does not match ohm or Celsius given
how problematic matching can be. This is planned
to be fixed in later versions.
if ( $sim->matchSymbol( $measure ) ){
print "It is a valid measure.\n";
}
=cut
sub matchSymbol{
my $self=$_[0];
my $measure=$_[1];
if ( ! $self->errorblank ){
$self->warnString('Failed to blank the previous error');
}
if ( ! defined( $measure ) ){
$self->{error}=1;
$self->{errorString}='No symbol specified';
$self->warn;
return undef;
}
my @keys=keys(%{$self->{keys}});
my $int=0;
while( defined( $keys[$int] ) ){
if (
( $self->{measures}{ $keys[$int] } ne 'ERROR' ) &&
( $self->{measures}{ $keys[$int] } eq $measure )
){
return 1;
}
$int++;
}
return 0;
}
=head1 ERROR CODES
This module is a Error::Helper ojbect so errors can be checked for
in the usual fashion.
=head2 1
No measure specified.
=head1 AUTHOR
Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>