File Coverage

unit.pm
Criterion Covered Total %
statement 33 34 97.0
branch n/a
condition 1 3 33.3
subroutine 12 13 92.3
pod n/a
total 46 50 92.0


line stmt bran cond sub pod time code
1             package Unit;
2              
3 1     1   6 use strict;
  1         2  
  1         28  
4 1     1   4 use warnings;
  1         2  
  1         23  
5              
6 1     1   4 use unitConverter;
  1         2  
  1         17  
7 1     1   349 use factor;
  1         2  
  1         24  
8 1     1   341 use transformedUnit;
  1         3  
  1         28  
9              
10             # heritage
11 1     1   6 use base qw( Factor );
  1         2  
  1         638  
12              
13             sub new {
14 29     29   48 my ( $class ) = @_;
15 29   33     60 $class = ref($class) || $class;
16 29         59 my $this = $class->SUPER::new();
17 29         42 bless($this, $class);
18 29         54 return $this;
19             }
20              
21             sub getConverterTo {
22 7     7   59 my ( $this, $target ) = @_;
23 7         14 return $target->toBase->inverse->concatenate($this->toBase);
24             }
25              
26             sub toBase {
27 0     0   0 die "abstract method toBase";
28             }
29              
30             sub shift {
31 1     1   7 my ( $this, $value ) = @_;
32 1         3 return TransformedUnit->new(UnitConverter->newTranslation($value), $this);
33             }
34              
35             sub scaleMultiply {
36 11     11   46 my ( $this, $value ) = @_;
37 11         25 return TransformedUnit->new(UnitConverter->newLinear($value), $this);
38             }
39              
40             sub scaleDivide {
41 4     4   22 my ( $this, $value ) = @_;
42 4         9 return $this->scaleMultiply(1.0 / $value);
43             }
44              
45             sub factor {
46 9     9   51 my ( $this, $numerator, $denominator ) = @_;
47 9         17 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;