| 1 | package Weather::Bug::Quantity; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 14 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 14 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | use overload | ||||||||||||||||||||||||||||
| 9 | 14 | ▶ | '""' => \&stringify; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 14 | our $VERSION = '0.25'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 14 | has 'value' => ( is => 'ro', isa => 'Str', init_arg => '-value' ); | |||||||||||||||||||||||||||
| 14 | 14 | has 'units' => ( is => 'ro', isa => 'Str', init_arg => '-units' ); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | sub from_xml | ||||||||||||||||||||||||||||
| 17 | 36 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
from_xml: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 36 | my $class = shift; | |||||||||||||||||||||||||||
| 19 | 36 | my $node = shift; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 36 | return Weather::Bug::Quantity->new( | |||||||||||||||||||||||||||
| 22 | -value => $node->findvalue( '.' ), | ||||||||||||||||||||||||||||
| 23 | -units => $node->findvalue( '@units' ), | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub _precision | ||||||||||||||||||||||||||||
| 28 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_precision: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 29 | 0 | my $value = shift; | |||||||||||||||||||||||||||
| 30 | 0 | my $dec = shift; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | return int($value) if 0 == $dec; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | return sprintf( "%.${dec}f", $value ); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | sub BUILD | ||||||||||||||||||||||||||||
| 37 | 149 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 38 | 149 | my $self = shift; | |||||||||||||||||||||||||||
| 39 | 149 | my $params = shift; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 149 | my $unit = $params->{'-units'}; | |||||||||||||||||||||||||||
| 42 | 149 | $unit =~ s/°//; | |||||||||||||||||||||||||||
| 43 | 149 | $unit =~ s/"/in/; | |||||||||||||||||||||||||||
| 44 | 149 | $self->{units} = $unit; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 149 | my $value = $params->{'-value'}; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 149 | ▶ | if( '--' eq $value || 'N/A' eq uc $value ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
"--" eq $value or "N/A" eq uc $value
MC/DC100%2/2
"--" eq $value or "N/A" eq uc $value
"--" eq $value
"N/A" eq uc $value
Truth table100%3/3
A or B
A= "--" eq $valueB= "N/A" eq uc $value
| |||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||
| 50 | 54 | $self->{value} = undef; | |||||||||||||||||||||||||||
| 51 | 54 | return; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 95 | $value =~ tr/-0-9.//cd; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 95 | $self->{value} = $value; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 95 | return; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | sub is_null | ||||||||||||||||||||||||||||
| 61 | 173 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
is_null: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 173 | my $self = shift; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 173 | return !defined( $self->value() ); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | sub stringify | ||||||||||||||||||||||||||||
| 68 | 12 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 12 | ▶ | return 'N/A' if $self->is_null(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 6 | return $self->value() . " " . $self->units(); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 14 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||