line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::Calc::Units::Convert::Base2Metric; |
2
|
1
|
|
|
1
|
|
6
|
use base 'Math::Calc::Units::Convert::Metric'; # Overrides |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
84
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
49
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use vars qw(%metric_base2 %abbrev $metric_prefix_test %pref); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
397
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
%metric_base2 = ( kilo => 2**10, |
8
|
|
|
|
|
|
|
mega => 2**20, |
9
|
|
|
|
|
|
|
giga => 2**30, |
10
|
|
|
|
|
|
|
tera => 2**40, |
11
|
|
|
|
|
|
|
peta => 2**50, |
12
|
|
|
|
|
|
|
exa => 2**60, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# No nanobytes, sorry |
16
|
|
|
|
|
|
|
%abbrev = ( k => 'kilo', |
17
|
|
|
|
|
|
|
m => 'mega', |
18
|
|
|
|
|
|
|
g => 'giga', |
19
|
|
|
|
|
|
|
t => 'tera', |
20
|
|
|
|
|
|
|
p => 'peta', |
21
|
|
|
|
|
|
|
e => 'exa', |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
%pref = ( unit => 1.0, |
25
|
|
|
|
|
|
|
kilo => 0.8, |
26
|
|
|
|
|
|
|
mega => 0.8, |
27
|
|
|
|
|
|
|
giga => 0.8, |
28
|
|
|
|
|
|
|
tera => 0.7, |
29
|
|
|
|
|
|
|
peta => 0.6, |
30
|
|
|
|
|
|
|
exa => 0.3, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub get_metric { |
34
|
203
|
|
|
203
|
0
|
292
|
my ($self, $what) = @_; |
35
|
203
|
|
|
|
|
1059
|
return $metric_base2{$what}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub get_abbrev { |
39
|
5
|
|
|
5
|
0
|
11
|
my ($self, $what) = @_; |
40
|
5
|
|
33
|
|
|
44
|
return $abbrev{$what} || $abbrev{lc($what)}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$metric_prefix_test = qr/^(${\join("|",keys %metric_base2)})/i; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub get_prefix { |
46
|
856
|
|
|
856
|
0
|
1152
|
my ($self, $what) = @_; |
47
|
856
|
100
|
|
|
|
4384
|
if ($what =~ $metric_prefix_test) { |
48
|
400
|
|
|
|
|
1739
|
return $1; |
49
|
|
|
|
|
|
|
} else { |
50
|
456
|
|
|
|
|
1916
|
return; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub prefix_pref { |
55
|
180
|
|
|
180
|
0
|
246
|
my ($self, $prefix) = @_; |
56
|
180
|
|
33
|
|
|
755
|
return $pref{lc($prefix)} || $pref{unit}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub get_prefixes { |
60
|
30
|
|
|
30
|
0
|
99
|
return keys %metric_base2; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Unnecessary efficiency hack: don't bother checking both upper & lower case |
64
|
|
|
|
|
|
|
sub expand { |
65
|
3
|
|
|
3
|
0
|
11
|
my ($self, $char) = @_; |
66
|
3
|
|
|
|
|
30
|
return $self->get_abbrev($char); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |