SIprefixes/hecto.pm untested

filter: Statementstmt 0.0% 0 / 66 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 104 CC 12 SCAR 30.4
CC
12
Cov
0%
shortMatch
42.0
longMatch
30.0
fromBase
6.0
CRAP 20.9
1 package Data::SIprefixes::hecto;
2  
3 use strict;
4 use warnings;
5 use bignum;
6 use base 'Error::Helper';
7  
8 =head1 NAME
9  
10 Data::SIprefixes::hecto - This provides hecto 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::hecto;
23
24 my $prefix=Data::SIprefixes::hecto->new;
25  
26 my $origMeasure='hectometer';
27
28 my $measure=$prefix->longMatch( $origMeasure );
29 my $long;
30 if ( $prefix->error ){
31 warn('error:'.$foo->error.': '.$foo->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::hecto->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=~/^hecto/ ){
114 my $origMeasure=$measure;
115 $measure=~s/^hecto//g;
116  
117 if ( $measure =~ /^ / ){
118 $self->{error}=2;
119 $self->{errorString}='Space found after prefix, /^exa/, 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 #avoid possible collisions
160 if ( $measure eq 'henry' ){
161 return $measure;
162 }
163  
164 if ( $measure=~/^h/ ){
165 my $origMeasure=$measure;
166 $measure=~s/^h//g;
167  
168 if ( $measure =~ /^ / ){
169 $self->{error}=2;
170 $self->{errorString}='Space found after prefix, /^E/, in "'.$origMeasure.'"' ;
171 $self->warn;
172 return undef;
173 }
174  
175 return $measure;
176 }
177  
178 return undef;
179 }
180  
181 =head2 symbol
182  
183 This returns the symbol for the prefix.
184  
185 my $symbol=$prefix->symbol;
186  
187 =cut
188  
189 sub symbol{
190 return 'h';
191 }
192  
193 =head2 toBase
194  
195 Returns the number needed to to multiple it by to get from the prefixed measure
196 number to the unprefixed measure.
197  
198 my $toBase=$prefix->toBase;
199  
200 =cut
201  
202 sub toBase{
203 my $self=$_[0];
204  
205 if ( ! $self->errorblank ){
206 $self->warnString('Failed to blank the previous error');
207 }
208  
209 return $self->toBase;
210 }
211  
212 =head1 ERROR CODES
213  
214 =head2 1
215  
216 Nothing passed for a measure.
217  
218 =head2 2
219  
220 Space found after prefix.
221  
222 =head1 AUTHOR
223  
224 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
225  
226 =head1 BUGS
227  
228 Please report any bugs or feature requests to C<bug-data-siprefixes at rt.cpan.org>, or through
229 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-SIprefixes>. I will be notified, and then you'll
230 automatically be notified of progress on your bug as I make changes.
231  
232  
233  
234  
235 =head1 SUPPORT
236  
237 You can find documentation for this module with the perldoc command.
238  
239 perldoc Data::SIprefixes::hecto
240  
241  
242 You can also look for information at:
243  
244 =over 4
245  
246 =item * RT: CPAN's request tracker (report bugs here)
247  
248 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-SIprefixes>
249  
250 =item * AnnoCPAN: Annotated CPAN documentation
251  
252 L<http://annocpan.org/dist/Data-SIprefixes>
253  
254 =item * CPAN Ratings
255  
256 L<http://cpanratings.perl.org/d/Data-SIprefixes>
257  
258 =item * Search CPAN
259  
260 L<http://search.cpan.org/dist/Data-SIprefixes/>
261  
262 =back
263  
264  
265 =head1 ACKNOWLEDGEMENTS
266  
267  
268 =head1 LICENSE AND COPYRIGHT
269  
270 Copyright 2012 Zane C. Bowers-Hadley.
271  
272 This program is free software; you can redistribute it and/or modify it
273 under the terms of either: the GNU General Public License as published
274 by the Free Software Foundation; or the Artistic License.
275  
276 See http://dev.perl.org/licenses/ for more information.
277  
278  
279 =cut
280  
281 1; # End of Data::SIprefixes::hecto