| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Data::SImeasures; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25941
|
use 5.006; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
40
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
44
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
31
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use base 'Error::Helper'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
975
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Data::SImeasures - The checks if something is a SI measure or not. |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.0.0 |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.0.0'; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Data::SImeasures; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $sim = Data::SImeasures->new; |
|
26
|
|
|
|
|
|
|
... |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
It is worth noting that some measures are present more than |
|
29
|
|
|
|
|
|
|
once as that is more than one common form. These are listed |
|
30
|
|
|
|
|
|
|
below. |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
amp |
|
33
|
|
|
|
|
|
|
ampere |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
meter |
|
36
|
|
|
|
|
|
|
metre |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Celsius |
|
39
|
|
|
|
|
|
|
degree Celsius |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
This module does have issues dealing with ohm and Celsius as |
|
42
|
|
|
|
|
|
|
when it comes to the symbol as depending on the source, it |
|
43
|
|
|
|
|
|
|
may be represented differently. This will be fixed eventually. |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 METHODS |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 new |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
This initilizes the object. |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $sim=Data::SImeasures->new; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub new{ |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
|
|
0
|
1
|
|
my $self={ |
|
58
|
|
|
|
|
|
|
perror=>undef, |
|
59
|
|
|
|
|
|
|
error=>undef, |
|
60
|
|
|
|
|
|
|
errorString=>'', |
|
61
|
|
|
|
|
|
|
}; |
|
62
|
0
|
|
|
|
|
|
bless $self; |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
$self->{measures}={ |
|
65
|
|
|
|
|
|
|
'amp'=>'A', |
|
66
|
|
|
|
|
|
|
'ampere'=>'A', |
|
67
|
|
|
|
|
|
|
'metre'=>'m', |
|
68
|
|
|
|
|
|
|
'meter'=>'m', |
|
69
|
|
|
|
|
|
|
'gram'=>'g', |
|
70
|
|
|
|
|
|
|
'second'=>'s', |
|
71
|
|
|
|
|
|
|
'kelvin'=>'K', |
|
72
|
|
|
|
|
|
|
'mole'=>'mol', |
|
73
|
|
|
|
|
|
|
'candela'=>'cd', |
|
74
|
|
|
|
|
|
|
'hertz'=>'Hz', |
|
75
|
|
|
|
|
|
|
'radian'=>'rad', |
|
76
|
|
|
|
|
|
|
'steradian'=>'sr', |
|
77
|
|
|
|
|
|
|
'newton'=>'N', |
|
78
|
|
|
|
|
|
|
'pascal'=>'Pa', |
|
79
|
|
|
|
|
|
|
'joule'=>'J', |
|
80
|
|
|
|
|
|
|
'watt'=>'W', |
|
81
|
|
|
|
|
|
|
'coulomb'=>'C', |
|
82
|
|
|
|
|
|
|
'volt'=>'V', |
|
83
|
|
|
|
|
|
|
'farad'=>'F', |
|
84
|
|
|
|
|
|
|
'ohm'=>'ERROR', |
|
85
|
|
|
|
|
|
|
'siemens'=>'S', |
|
86
|
|
|
|
|
|
|
'weber'=>'Wb', |
|
87
|
|
|
|
|
|
|
'tesla'=>'T', |
|
88
|
|
|
|
|
|
|
'henry'=>'H', |
|
89
|
|
|
|
|
|
|
'degree Celsius'=>'ERROR', |
|
90
|
|
|
|
|
|
|
'Celsius'=>'ERROR', |
|
91
|
|
|
|
|
|
|
'lumen'=>'lm', |
|
92
|
|
|
|
|
|
|
'lux'=>'lx', |
|
93
|
|
|
|
|
|
|
'becquere'=>'Bq', |
|
94
|
|
|
|
|
|
|
'gray'=>'Gy', |
|
95
|
|
|
|
|
|
|
'sievert'=>'Sv', |
|
96
|
|
|
|
|
|
|
'katal'=>'kat', |
|
97
|
|
|
|
|
|
|
}; |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
return $self; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 getSymbol |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This returns the symbol for the specified measure. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
If if it ohm or Celsius, undef is returned. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $symbol=$self->getSymbol( $symbol ); |
|
109
|
|
|
|
|
|
|
if ( $sim->error ){ |
|
110
|
|
|
|
|
|
|
warn('Failed to match the specified measure'); |
|
111
|
|
|
|
|
|
|
}else{ |
|
112
|
|
|
|
|
|
|
if ( ! defined( $symbol ) ){ |
|
113
|
|
|
|
|
|
|
warn( $measure.' is does not have a supported symbol' ); |
|
114
|
|
|
|
|
|
|
}else{ |
|
115
|
|
|
|
|
|
|
print "The symbol for ".$measure." is ".$symbol."\n"; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub getSymbol{ |
|
122
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
123
|
0
|
|
|
|
|
|
my $measure=$_[1]; |
|
124
|
|
|
|
|
|
|
|
|
125
|
0
|
0
|
|
|
|
|
if ( ! $self->errorblank ){ |
|
126
|
0
|
|
|
|
|
|
$self->warnString('Failed to blank the previous error'); |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
0
|
0
|
|
|
|
|
if ( ! defined( $measure ) ){ |
|
130
|
0
|
|
|
|
|
|
$self->{error}=1; |
|
131
|
0
|
|
|
|
|
|
$self->{errorString}='No measure specified'; |
|
132
|
0
|
|
|
|
|
|
$self->warn; |
|
133
|
0
|
|
|
|
|
|
return undef; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
0
|
0
|
|
|
|
|
if ( ! $self->match( $measure ) ){ |
|
137
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
138
|
0
|
|
|
|
|
|
$self->{errorString}=''; |
|
139
|
0
|
|
|
|
|
|
$self->warn; |
|
140
|
0
|
|
|
|
|
|
return undef; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
my $symbol=$self->{measures}{$measure}; |
|
144
|
0
|
0
|
|
|
|
|
if ( $symbol eq 'ERROR' ){ |
|
145
|
0
|
|
|
|
|
|
return undef; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
return $symbol; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 match |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This matches measures. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This only matches the name, not the symbol. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
If ends in an s, plural, and does not match |
|
158
|
|
|
|
|
|
|
siemens or Celsius, the end s is removed. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
'1' is returned on it being matched and '0' |
|
161
|
|
|
|
|
|
|
if it is not. |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
As long as an measure is defined, it wont error. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
if ( $sim->match( $measure ) ){ |
|
166
|
|
|
|
|
|
|
print "It is a valid measure.\n"; |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub match{ |
|
172
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
173
|
0
|
|
|
|
|
|
my $measure=$_[1]; |
|
174
|
|
|
|
|
|
|
|
|
175
|
0
|
0
|
|
|
|
|
if ( ! $self->errorblank ){ |
|
176
|
0
|
|
|
|
|
|
$self->warnString('Failed to blank the previous error'); |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
0
|
0
|
|
|
|
|
if ( ! defined( $measure ) ){ |
|
180
|
0
|
|
|
|
|
|
$self->{error}=1; |
|
181
|
0
|
|
|
|
|
|
$self->{errorString}='No measure specified'; |
|
182
|
0
|
|
|
|
|
|
$self->warn; |
|
183
|
0
|
|
|
|
|
|
return undef; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
#remove the end S if it is plural |
|
187
|
0
|
0
|
0
|
|
|
|
if ( |
|
|
|
|
0
|
|
|
|
|
|
188
|
|
|
|
|
|
|
( $measure=~/s$/ ) && |
|
189
|
|
|
|
|
|
|
( $measure!~/siemens$/ ) && |
|
190
|
|
|
|
|
|
|
( $measure!~/Celsius$/ ) |
|
191
|
|
|
|
|
|
|
){ |
|
192
|
0
|
|
|
|
|
|
$measure=~s/s$//; |
|
193
|
|
|
|
|
|
|
} |
|
194
|
|
|
|
|
|
|
|
|
195
|
0
|
0
|
|
|
|
|
if ( defined( $self->{measures}{$measure} ) ){ |
|
196
|
0
|
|
|
|
|
|
return 1; |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
return 0; |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head2 matchAll |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
This matches either the symbol or the name of the measure. |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
if ( $sim->matchAll( $measure ) ){ |
|
207
|
|
|
|
|
|
|
print "It is a valid measure.\n"; |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=cut |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub matchAll{ |
|
213
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
214
|
0
|
|
|
|
|
|
my $measure=$_[1]; |
|
215
|
|
|
|
|
|
|
|
|
216
|
0
|
0
|
|
|
|
|
if ( ! $self->errorblank ){ |
|
217
|
0
|
|
|
|
|
|
$self->warnString('Failed to blank the previous error'); |
|
218
|
|
|
|
|
|
|
} |
|
219
|
|
|
|
|
|
|
|
|
220
|
0
|
0
|
|
|
|
|
if ( ! defined( $measure ) ){ |
|
221
|
0
|
|
|
|
|
|
$self->{error}=1; |
|
222
|
0
|
|
|
|
|
|
$self->{errorString}='No symbol specified'; |
|
223
|
0
|
|
|
|
|
|
$self->warn; |
|
224
|
0
|
|
|
|
|
|
return undef; |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
|
|
227
|
0
|
0
|
|
|
|
|
if ( $self->match( $measure ) ){ |
|
228
|
0
|
|
|
|
|
|
return 1; |
|
229
|
|
|
|
|
|
|
} |
|
230
|
|
|
|
|
|
|
|
|
231
|
0
|
0
|
|
|
|
|
if ( $self->matchSymbol( $measure ) ){ |
|
232
|
0
|
|
|
|
|
|
return 1; |
|
233
|
|
|
|
|
|
|
} |
|
234
|
|
|
|
|
|
|
|
|
235
|
0
|
|
|
|
|
|
return undef; |
|
236
|
|
|
|
|
|
|
} |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head2 matchSymbol |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
This matches measure symbols. |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
'1' is returned on it being matched and '0' |
|
243
|
|
|
|
|
|
|
if it is not. |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
As long as an measure is defined, it wont error. |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
This currently does not match ohm or Celsius given |
|
248
|
|
|
|
|
|
|
how problematic matching can be. This is planned |
|
249
|
|
|
|
|
|
|
to be fixed in later versions. |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
if ( $sim->matchSymbol( $measure ) ){ |
|
252
|
|
|
|
|
|
|
print "It is a valid measure.\n"; |
|
253
|
|
|
|
|
|
|
} |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=cut |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
sub matchSymbol{ |
|
258
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
259
|
0
|
|
|
|
|
|
my $measure=$_[1]; |
|
260
|
|
|
|
|
|
|
|
|
261
|
0
|
0
|
|
|
|
|
if ( ! $self->errorblank ){ |
|
262
|
0
|
|
|
|
|
|
$self->warnString('Failed to blank the previous error'); |
|
263
|
|
|
|
|
|
|
} |
|
264
|
|
|
|
|
|
|
|
|
265
|
0
|
0
|
|
|
|
|
if ( ! defined( $measure ) ){ |
|
266
|
0
|
|
|
|
|
|
$self->{error}=1; |
|
267
|
0
|
|
|
|
|
|
$self->{errorString}='No symbol specified'; |
|
268
|
0
|
|
|
|
|
|
$self->warn; |
|
269
|
0
|
|
|
|
|
|
return undef; |
|
270
|
|
|
|
|
|
|
} |
|
271
|
|
|
|
|
|
|
|
|
272
|
0
|
|
|
|
|
|
my @keys=keys(%{$self->{keys}}); |
|
|
0
|
|
|
|
|
|
|
|
273
|
0
|
|
|
|
|
|
my $int=0; |
|
274
|
0
|
|
|
|
|
|
while( defined( $keys[$int] ) ){ |
|
275
|
0
|
0
|
0
|
|
|
|
if ( |
|
276
|
|
|
|
|
|
|
( $self->{measures}{ $keys[$int] } ne 'ERROR' ) && |
|
277
|
|
|
|
|
|
|
( $self->{measures}{ $keys[$int] } eq $measure ) |
|
278
|
|
|
|
|
|
|
){ |
|
279
|
0
|
|
|
|
|
|
return 1; |
|
280
|
|
|
|
|
|
|
} |
|
281
|
|
|
|
|
|
|
|
|
282
|
0
|
|
|
|
|
|
$int++; |
|
283
|
|
|
|
|
|
|
} |
|
284
|
|
|
|
|
|
|
|
|
285
|
0
|
|
|
|
|
|
return 0; |
|
286
|
|
|
|
|
|
|
} |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=head1 ERROR CODES |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
This module is a Error::Helper ojbect so errors can be checked for |
|
291
|
|
|
|
|
|
|
in the usual fashion. |
|
292
|
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=head2 1 |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
No measure specified. |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=head1 AUTHOR |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
Zane C. Bowers-Hadley, C<< >> |
|
300
|
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=head1 BUGS |
|
302
|
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
304
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
305
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
=head1 SUPPORT |
|
311
|
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
313
|
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
perldoc Data::SImeasures |
|
315
|
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
You can also look for information at: |
|
318
|
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=over 4 |
|
320
|
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
|
322
|
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
L |
|
324
|
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
326
|
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
L |
|
328
|
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
330
|
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
L |
|
332
|
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
=item * Search CPAN |
|
334
|
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
L |
|
336
|
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
=back |
|
338
|
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
341
|
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
344
|
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
Copyright 2012 Zane C. Bowers-Hadley. |
|
346
|
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
348
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
349
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
350
|
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
352
|
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
=cut |
|
355
|
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
1; # End of Data::SImeasures |