line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::Calc::Units::Convert::Combo; |
2
|
1
|
|
|
1
|
|
5
|
use base 'Math::Calc::Units::Convert::Base2Metric'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
89
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
5
|
use vars qw(%units %metric_units %prefixable_metric_units %total_unit_map); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
71
|
|
5
|
1
|
|
|
1
|
|
6
|
use vars qw(%ranges %pref); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
564
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
%units = ( |
8
|
|
|
|
|
|
|
); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
%metric_units = ( |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
%prefixable_metric_units = ( bps => [ 1, { bit => 1, sec => -1 } ] ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
%ranges = ( default => [ 1, 999 ] ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
%pref = ( default => 1 ); |
18
|
|
|
|
|
|
|
|
19
|
24
|
|
|
24
|
0
|
45
|
sub canonical_unit { return; } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub unit_map { |
22
|
74
|
|
|
74
|
0
|
96
|
my ($self) = @_; |
23
|
74
|
100
|
|
|
|
338
|
if (keys %total_unit_map == 0) { |
24
|
1
|
|
|
|
|
2
|
%total_unit_map = (%{$self->SUPER::unit_map()}, |
|
1
|
|
|
|
|
10
|
|
25
|
|
|
|
|
|
|
%units, |
26
|
|
|
|
|
|
|
%metric_units, |
27
|
|
|
|
|
|
|
%prefixable_metric_units); |
28
|
|
|
|
|
|
|
} |
29
|
74
|
|
|
|
|
195
|
return \%total_unit_map; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Singular("Mbps") is Mbps, not Mbp |
33
|
|
|
|
|
|
|
sub singular { |
34
|
125
|
|
|
125
|
0
|
230
|
my ($self, $unit) = @_; |
35
|
125
|
100
|
|
|
|
805
|
return $self->SUPER::singular($unit) unless $unit =~ /bps$/; |
36
|
2
|
|
|
|
|
8
|
return $unit; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# demetric : string => mult x base |
40
|
|
|
|
|
|
|
# |
41
|
|
|
|
|
|
|
sub demetric { |
42
|
152
|
|
|
152
|
0
|
205
|
my ($self, $string) = @_; |
43
|
152
|
100
|
|
|
|
815
|
if (my $prefix = $self->get_prefix($string)) { |
|
|
100
|
|
|
|
|
|
44
|
19
|
|
|
|
|
162
|
my $tail = lc($self->singular(substr($string, length($prefix)))); |
45
|
19
|
50
|
|
|
|
67
|
if ($metric_units{$tail}) { |
46
|
0
|
|
|
|
|
0
|
return ($self->get_metric($prefix), $tail); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} elsif (my $abbrev = $self->get_abbrev_prefix($string)) { |
49
|
32
|
|
|
|
|
144
|
my $tail = lc($self->singular(substr($string, length($abbrev)))); |
50
|
32
|
100
|
|
|
|
308
|
if ($prefixable_metric_units{$tail}) { |
51
|
2
|
|
|
|
|
16
|
my $prefix = $self->get_abbrev($abbrev); |
52
|
2
|
|
|
|
|
14
|
return ($self->get_metric($prefix), $tail); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
150
|
|
|
|
|
782
|
return (1, $string); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# to_canonical : unitName -> amount x unitName |
60
|
|
|
|
|
|
|
# |
61
|
11
|
|
|
11
|
0
|
48
|
sub to_canonical { return; } |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub lookup_compound { |
64
|
76
|
|
|
76
|
0
|
104
|
my ($self, $unitName) = @_; |
65
|
|
|
|
|
|
|
|
66
|
76
|
|
|
|
|
396
|
foreach (keys %units, keys %metric_units, keys %prefixable_metric_units) { |
67
|
76
|
100
|
|
|
|
291
|
if (my $mult = $self->simple_convert($unitName, $_)) { |
68
|
2
|
|
33
|
|
|
24
|
my $u = $units{$_} |
69
|
|
|
|
|
|
|
|| $metric_units{$_} |
70
|
|
|
|
|
|
|
|| $prefixable_metric_units{$_}; |
71
|
2
|
|
|
|
|
14
|
return [ $mult * $u->[0], $u->[1] ]; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
74
|
|
|
|
|
266
|
return; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub get_ranges { |
79
|
0
|
|
|
0
|
0
|
|
return \%ranges; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub get_prefs { |
83
|
0
|
|
|
0
|
0
|
|
return \%pref; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |