| 1 | package Math::Calc::Units::Convert::Combo; | ||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use base 'Math::Calc::Units::Convert::Base2Metric'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use vars qw(%units %metric_units %prefixable_metric_units %total_unit_map); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use vars qw(%ranges %pref); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 1 | %units = ( | |||||||||||||||||||||||||||||||||
| 8 | ); | ||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | 1 | %metric_units = ( | |||||||||||||||||||||||||||||||||
| 11 | ); | ||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | 1 | %prefixable_metric_units = ( bps => [ 1, { bit => 1, sec => -1 } ] ); | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | 1 | %ranges = ( default => [ 1, 999 ] ); | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 1 | %pref = ( default => 1 ); | |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | 24 | ▶ | sub canonical_unit { return; } | ||||||||||||||||||||||||||||||||
|
Subroutine
canonical_unit: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | 74 | ▶ | sub unit_map { | ||||||||||||||||||||||||||||||||
|
Subroutine
unit_map: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 22 | 74 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 23 | 74 | ▶ | if (keys %total_unit_map == 0) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 24 | 1 | %total_unit_map = (%{$self->SUPER::unit_map()}, | |||||||||||||||||||||||||||||||||
| 25 | %units, | ||||||||||||||||||||||||||||||||||
| 26 | %metric_units, | ||||||||||||||||||||||||||||||||||
| 27 | %prefixable_metric_units); | ||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||
| 29 | 74 | return \%total_unit_map; | |||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | # Singular("Mbps") is Mbps, not Mbp | ||||||||||||||||||||||||||||||||||
| 33 | 125 | ▶ | sub singular { | ||||||||||||||||||||||||||||||||
|
Subroutine
singular: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 34 | 125 | my ($self, $unit) = @_; | |||||||||||||||||||||||||||||||||
| 35 | 125 | ▶ | return $self->SUPER::singular($unit) unless $unit =~ /bps$/; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 36 | 2 | return $unit; | |||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | # demetric : string => mult x base | ||||||||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||||||||
| 41 | 152 | ▶ | sub demetric { | ||||||||||||||||||||||||||||||||
|
Subroutine
demetric: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 42 | 152 | my ($self, $string) = @_; | |||||||||||||||||||||||||||||||||
| 43 | 152 | ▶ | if (my $prefix = $self->get_prefix($string)) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 44 | 19 | my $tail = lc($self->singular(substr($string, length($prefix)))); | |||||||||||||||||||||||||||||||||
| 45 | 19 | ▶ | if ($metric_units{$tail}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 46 | 0 | return ($self->get_metric($prefix), $tail); | |||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||
| 48 | } elsif (my $abbrev = $self->get_abbrev_prefix($string)) { | ||||||||||||||||||||||||||||||||||
| 49 | 32 | my $tail = lc($self->singular(substr($string, length($abbrev)))); | |||||||||||||||||||||||||||||||||
| 50 | 32 | ▶ | if ($prefixable_metric_units{$tail}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 51 | 2 | my $prefix = $self->get_abbrev($abbrev); | |||||||||||||||||||||||||||||||||
| 52 | 2 | return ($self->get_metric($prefix), $tail); | |||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | 150 | return (1, $string); | |||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | # to_canonical : unitName -> amount x unitName | ||||||||||||||||||||||||||||||||||
| 60 | # | ||||||||||||||||||||||||||||||||||
| 61 | 11 | ▶ | sub to_canonical { return; } | ||||||||||||||||||||||||||||||||
|
Subroutine
to_canonical: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | 76 | ▶ | sub lookup_compound { | ||||||||||||||||||||||||||||||||
|
Subroutine
lookup_compound: called CC=5 SCAR=17.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 64 | 76 | my ($self, $unitName) = @_; | |||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | 76 | foreach (keys %units, keys %metric_units, keys %prefixable_metric_units) { | |||||||||||||||||||||||||||||||||
| 67 | 76 | ▶ | if (my $mult = $self->simple_convert($unitName, $_)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 68 | my $u = $units{$_} | ||||||||||||||||||||||||||||||||||
| 69 | || $metric_units{$_} | ||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | || $prefixable_metric_units{$_}; | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
$Math::Calc::Units::Convert::Combo::units{$_} || $Math::Calc::Units::Convert::Combo::metric_units{$_} || $Math::Calc::Units::Convert::Combo::prefixable_metric_units{$_}
$Math::Calc::Units::Convert::Combo::units{$_} or $Math::Calc::Units::Convert::Combo::metric_units{$_}
MC/DC0%0/3
$Math::Calc::Units::Convert::Combo::units{$_} || $Math::Calc::Units::Convert::Combo::metric_units{$_} || $Math::Calc::Units::Convert::Combo::prefixable_metric_units{$_}
$Math::Calc::Units::Convert::Combo::units{$_}
$Math::Calc::Units::Convert::Combo::metric_units{$_}
$Math::Calc::Units::Convert::Combo::prefixable_metric_units{$_}
Truth table25%1/4
A or B || C
A= $Math::Calc::Units::Convert::Combo::units{$_}B= $Math::Calc::Units::Convert::Combo::metric_units{$_}C= $Math::Calc::Units::Convert::Combo::prefixable_metric_units{$_}
| |||||||||||||||||||||||||||||||||||
| 71 | 2 | return [ $mult * $u->[0], $u->[1] ]; | |||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | 74 | return; | |||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub get_ranges { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_ranges: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 79 | 0 | return \%ranges; | |||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub get_prefs { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_prefs: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 83 | 0 | return \%pref; | |||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | 1 | 1; | |||||||||||||||||||||||||||||||||