unit.pm

filter: Statementstmt 97.1% 34 / 35 Branchbran n/a Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 92.3% 12 / 13 Podpod n/a totaltotal 88.6% 47 / 53 CC 2 SCAR 2.0
CC
2
Cov
92%
new
2.1
toBase
2.0
BEGIN
1.0
CRAP 1.2
« fundamentalUnit.pm ↑ Summary transformedUnit.pm »
1 package Unit;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use unitConverter;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use factor;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use transformedUnit;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # heritage
11 1 ▶use base qw( Factor );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 29 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
14 29 my ( $class ) = @_;
15 29 ▶ $class = ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0290
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
16 29 my $this = $class->SUPER::new();
17 29 bless($this, $class);
18 29 return $this;
19 }
20  
21 7 ▶sub getConverterTo {
Subroutine getConverterTo: called CC=1 SCAR=0.0
22 7 my ( $this, $target ) = @_;
23 7 return $target->toBase->inverse->concatenate($this->toBase);
24 }
25  
26 0 ▶sub toBase {
Subroutine toBase: not called CC=1 SCAR=6.9
27 0 die "abstract method toBase";
28 }
29  
30 1 ▶sub shift {
Subroutine shift: called CC=1 SCAR=0.0
31 1 my ( $this, $value ) = @_;
32 1 return TransformedUnit->new(UnitConverter->newTranslation($value), $this);
33 }
34  
35 11 ▶sub scaleMultiply {
Subroutine scaleMultiply: called CC=1 SCAR=0.0
36 11 my ( $this, $value ) = @_;
37 11 return TransformedUnit->new(UnitConverter->newLinear($value), $this);
38 }
39  
40 4 ▶sub scaleDivide {
Subroutine scaleDivide: called CC=1 SCAR=0.0
41 4 my ( $this, $value ) = @_;
42 4 return $this->scaleMultiply(1.0 / $value);
43 }
44  
45 9 ▶sub factor {
Subroutine factor: called CC=1 SCAR=0.0
46 9 my ( $this, $numerator, $denominator ) = @_;
47 9 return Factor->new($this, $numerator, $denominator);
48 }
49  
50 =head1 NAME
51  
52 Unit - representation of an abstract unit
53  
54 =head1 DESCRIPTION
55  
56 This module maps a conceptual class that represents an abstract unit of measurement.
57  
58 =head1 AUTHOR
59  
60 Samuel Andres
61  
62 =head1 LICENSE
63  
64 UnLicense
65  
66 =cut
67  
68 1 1;
« fundamentalUnit.pm ↑ Summary transformedUnit.pm »