Bug/Temperature.pm

filter: Statementstmt 98.0% 51 / 52 Branchbran 87.5% 14 / 16 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 66.6% 2 / 3 totaltotal 91.7% 78 / 85 CC 10 SCAR 10.7
CC
10
Cov
94%
BUILD
5.0
from_xml
3.1
stringify
3.0
CRAP 2.9
« Bug/Station.pm ↑ Summary Bug/Quantity.pm »
1 package Weather::Bug::Temperature;
2  
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 use overload
9 13 ▶ '""' => \&stringify;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 13 our $VERSION = '0.25';
12  
13 13 extends 'Weather::Bug::Quantity';
14  
15 13 has 'f' => ( is => 'ro', isa => 'Num', default => 0.0 );
16 13 has 'c' => ( is => 'ro', isa => 'Num', default => 0.0 );
17 13 has 'is_SI' => ( is => 'rw', isa => 'Bool', init_arg => '-si' );
18  
19 sub from_xml
20 102 ▶{
Subroutine from_xml: called CC=3 SCAR=11.3
Pod documented
21 102 my $class = shift;
22 102 my $node = shift;
23  
24 102 ▶ die "No node found.\n" unless defined $node;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 102 102
25  
26 102 ▶ return Weather::Bug::Temperature->new(
Condition66%2/3
$node->findvalue('@unit') || $node->findvalue('@units')
l!l&&r!l&&!r
78240
MC/DC0%0/2
$node->findvalue('@unit') || $node->findvalue('@units')
$node->findvalue('@unit') $node->findvalue('@units')
Truth table66%2/3
A || B
A= $node->findvalue('@unit')B= $node->findvalue('@units')
ABresult
1X1
011
000
27 -value => $node->findvalue( '.' ),
28 -units => ($node->findvalue( '@unit' ) || $node->findvalue( '@units' )),
29 );
30 }
31  
32 sub _precision
33 68 ▶{
Subroutine _precision: called CC=2 SCAR=6.9
34 68 my $value = shift;
35 68 my $dec = shift;
36  
37 68 ▶ return int($value) if 0 == $dec;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == $dec 54 14 68
38 14 return sprintf( "%.${dec}f", $value );
39 }
40  
41 sub BUILD
42 107 ▶{
Subroutine BUILD: called CC=5 SCAR=16.1
Pod undocumented
43 107 my $self = shift;
44 107 my $params = shift;
45  
46 107 my $unit = $params->{'-units'};
47 107 $unit =~ s/°//;
48  
49 107 my $value = $params->{'-value'};
50 107 $value =~ tr/-0-9.//cd;
51  
52 107 ▶ if( '--' eq $value )
Branch: 1 branch
BranchTrueFalseTotal
if ("--" eq $value) 39 68 107
53 {
54 39 $self->{is_SI} = undef;
55 39 return;
56 }
57  
58 68 my $dec = 0;
59 68 ▶ $dec = length $1 if $value =~ /\.(\d+)/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\.(\d+)/ 14 54 68
60  
61 68 ▶ if( $unit eq 'C' )
Branch: 2 branches
BranchTrueFalseTotal
if ($unit eq 'C') { } 2 66 68
elsif ($unit eq 'F') { } 66 0 66
62 {
63 2 $self->{is_SI} = 1;
64 2 $self->{f} = _precision( $value*1.8 + 32, $dec );
65 2 $self->{c} = $value;
66 }
67 elsif( $unit eq 'F' )
68 {
69 66 $self->{is_SI} = 0;
70 66 $self->{c} = _precision( ($value-32)/1.8, $dec );
71 66 $self->{f} = $value;
72 }
73 else
74 {
75 0 die "Unknown units for temperature.\n";
76 }
77  
78 68 return;
79 }
80  
81 sub stringify
82 14 ▶{
Subroutine stringify: called CC=3 SCAR=11.0
Pod documented
83 14 my $self = shift;
84  
85 14 ▶ return 'N/A' if $self->is_null();
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_null 2 12 14
86 12 ▶ return $self->is_SI() ? ($self->c() . " C") : ($self->f() . " F");
Branch: 1 branch
BranchTrueFalseTotal
$self->is_SI ? : 6 6 12
87 }
88  
89 13 1; # Magic true value required at end of module
90 __END__
« Bug/Station.pm ↑ Summary Bug/Quantity.pm »