| 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
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 102 | ▶ | return Weather::Bug::Temperature->new( | ||||||||||||||||||
|
Condition66%2/3
$node->findvalue('@unit') || $node->findvalue('@units')
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')
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 68 | ▶ | if( $unit eq 'C' ) | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 86 | 12 | ▶ | return $self->is_SI() ? ($self->c() . " C") : ($self->f() . " F"); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 13 | 1; # Magic true value required at end of module | |||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||