File Coverage

blib/lib/Data/SIprefixes/centi.pm
Criterion Covered Total %
statement 12 63 19.0
branch 0 20 0.0
condition n/a
subroutine 4 10 40.0
pod 6 6 100.0
total 22 99 22.2


line stmt bran cond sub pod time code
1             package Data::SIprefixes::centi;
2              
3 1     1   20973 use strict;
  1         2  
  1         24  
4 1     1   6 use warnings;
  1         2  
  1         26  
5 1     1   757 use bignum;
  1         7963  
  1         6  
6 1     1   65346 use base 'Error::Helper';
  1         3  
  1         799  
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 0     0 1   my $string=$_[1];
52              
53 0           my $self={
54             perror=>undef,
55             error=>undef,
56             errorString=>'',
57             fromBase=>0.01,
58             toBase=>100,
59             };
60 0           bless $self;
61            
62 0           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 0     0 1   my $self=$_[0];
76              
77 0 0         if ( ! $self->errorblank ){
78 0           $self->warnString('Failed to blank the previous error');
79             }
80              
81 0           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 0     0 1   my $self=$_[0];
100 0           my $measure=$_[1];
101              
102 0 0         if ( ! $self->errorblank ){
103 0           $self->warnString('Failed to blank the previous error');
104             }
105              
106 0 0         if ( ! defined( $measure ) ){
107 0           $self->{error}=1;
108 0           $self->{errorString}='No measure defined';
109 0           $self->warn;
110 0           return undef;
111             }
112              
113 0 0         if ( $measure=~/^centi/ ){
114 0           my $origMeasure=$measure;
115 0           $measure=~s/^centi//g;
116              
117 0 0         if ( $measure =~ /^ / ){
118 0           $self->{error}=2;
119 0           $self->{errorString}='Space found after prefix, /^centi/, in "'.$origMeasure.'"' ;
120 0           $self->warn;
121 0           return undef;
122             }
123              
124 0           return $measure;
125             }
126              
127 0           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 0     0 1   my $self=$_[0];
146 0           my $measure=$_[1];
147              
148 0 0         if ( ! $self->errorblank ){
149 0           $self->warnString('Failed to blank the previous error');
150             }
151              
152 0 0         if ( ! defined( $measure ) ){
153 0           $self->{error}=1;
154 0           $self->{errorString}='No measure defined';
155 0           $self->warn;
156 0           return undef;
157             }
158              
159 0 0         if ( $measure=~/^c/ ){
160 0           my $origMeasure=$measure;
161 0           $measure=~s/^c//g;
162              
163 0 0         if ( $measure =~ /^ / ){
164 0           $self->{error}=2;
165 0           $self->{errorString}='Space found after prefix, /^c/, in "'.$origMeasure.'"' ;
166 0           $self->warn;
167 0           return undef;
168             }
169              
170 0           return $measure;
171             }
172              
173 0           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 0     0 1   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 0     0 1   my $self=$_[0];
199              
200 0 0         if ( ! $self->errorblank ){
201 0           $self->warnString('Failed to blank the previous error');
202             }
203              
204 0           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<< >>
220              
221             =head1 BUGS
222              
223             Please report any bugs or feature requests to C, or through
224             the web interface at L. 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
244              
245             =item * AnnoCPAN: Annotated CPAN documentation
246              
247             L
248              
249             =item * CPAN Ratings
250              
251             L
252              
253             =item * Search CPAN
254              
255             L
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