| 1 | package Weather::Bug::Weather; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use Weather::Bug::Station; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use Weather::Bug::Temperature; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 12 | ▶ | use Weather::Bug::Quantity; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 12 | ▶ | use DateTime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 12 | our $VERSION = '0.25'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 11 | ▶ | subtype 'DateTime' => as 'Object' => where { $_->isa('DateTime') }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 12 | has 'date' => ( is => 'ro', isa => 'DateTime', init_arg => '-date' ); | |||||||||||||||||||||||||||
| 18 | 12 | has 'station' => ( is => 'ro', isa => 'Weather::Bug::Station', init_arg => '-station' ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 12 | has 'aux_temp' => ( is => 'ro', isa => 'Weather::Bug::Temperature', init_arg => '-aux_temp' ); | |||||||||||||||||||||||||||
| 21 | 12 | has 'aux_temp_rate' => ( is => 'ro', isa => 'Weather::Bug::Temperature', init_arg => '-aux_rate' ); | |||||||||||||||||||||||||||
| 22 | 12 | has 'dew_point' => ( is => 'ro', isa => 'Weather::Bug::Temperature', init_arg => '-dewpt' ); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 12 | has 'elevation' => ( is => 'ro', isa => 'Weather::Bug::Quantity', init_arg => '-elevation' ); | |||||||||||||||||||||||||||
| 25 | 12 | has 'feels_like' => ( is => 'ro', isa => 'Weather::Bug::Temperature', init_arg => '-feels' ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 12 | has 'gust_time' => ( is => 'ro', isa => 'DateTime', init_arg => '-gust_time' ); | |||||||||||||||||||||||||||
| 28 | 12 | has 'gust_speed' => ( is => 'ro', isa => 'Weather::Bug::Quantity', init_arg => '-gust_speed' ); | |||||||||||||||||||||||||||
| 29 | 12 | has 'gust_dir' => ( is => 'ro', isa => 'Str', init_arg => '-gust_dir' ); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 12 | has 'humidity' => ( is => 'ro', isa => 'Weather::Bug::Quantity', init_arg => '-humidity' ); | |||||||||||||||||||||||||||
| 32 | 12 | has 'humidity_high' => ( is => 'ro', isa => 'Weather::Bug::Quantity', init_arg => '-humidity_high' ); | |||||||||||||||||||||||||||
| 33 | 12 | has 'humidity_low' => ( is => 'ro', isa => 'Weather::Bug::Quantity', init_arg => '-humidity_low' ); | |||||||||||||||||||||||||||
| 34 | 12 | has 'humidity_rate' => ( is => 'ro', isa => 'Num', init_arg => '-humidity_rate' ); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 12 | has 'indoor_temp' => ( is => 'ro', isa => 'Weather::Bug::Temperature', init_arg => '-indoor_temp' ); | |||||||||||||||||||||||||||
| 37 | 12 | has 'indoor_temp_rate' => ( is => 'ro', isa => 'Weather::Bug::Temperature', init_arg => '-indoor_temp_rate' ); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 12 | has 'light' => ( is => 'ro', isa => 'Num', init_arg => '-light' ); | |||||||||||||||||||||||||||
| 40 | 12 | has 'light_rate' => ( is => 'ro', isa => 'Num', init_arg => '-light_rate' ); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 12 | has 'moon_phase' => ( is => 'ro', isa => 'Num', init_arg => '-moon_phase' ); | |||||||||||||||||||||||||||
| 43 | 12 | has 'moon_phase_img' => ( is => 'ro', isa => 'Str', init_arg => '-moon_phase_img' ); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 12 | has 'pressure' => ( is => 'ro', isa => 'Weather::Bug::Quantity', init_arg => '-pressure' ); | |||||||||||||||||||||||||||
| 46 | 12 | has 'pressure_high' => ( is => 'ro', isa => 'Weather::Bug::Quantity', init_arg => '-pressure_high' ); | |||||||||||||||||||||||||||
| 47 | 12 | has 'pressure_low' => ( is => 'ro', isa => 'Weather::Bug::Quantity', init_arg => '-pressure_low' ); | |||||||||||||||||||||||||||
| 48 | 12 | has 'pressure_rate' => ( is => 'ro', isa => 'Num', init_arg => '-pressure_rate' ); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 12 | has 'rain_month' => ( is => 'ro', isa => 'Weather::Bug::Quantity', init_arg => '-rain_month' ); | |||||||||||||||||||||||||||
| 51 | 12 | has 'rain_rate' => ( is => 'ro', isa => 'Weather::Bug::Quantity', init_arg => '-rain_rate' ); | |||||||||||||||||||||||||||
| 52 | 12 | has 'rain_rate_max' => ( is => 'ro', isa => 'Weather::Bug::Quantity', init_arg => '-rain_rate_max' ); | |||||||||||||||||||||||||||
| 53 | 12 | has 'rain_today' => ( is => 'ro', isa => 'Weather::Bug::Quantity', init_arg => '-rain_today' ); | |||||||||||||||||||||||||||
| 54 | 12 | has 'rain_year' => ( is => 'ro', isa => 'Weather::Bug::Quantity', init_arg => '-rain_year' ); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 12 | has 'temp' => ( is => 'ro', isa => 'Weather::Bug::Temperature', init_arg => '-temp' ); | |||||||||||||||||||||||||||
| 57 | 12 | has 'temp_high' => ( is => 'ro', isa => 'Weather::Bug::Temperature', init_arg => '-temp_high' ); | |||||||||||||||||||||||||||
| 58 | 12 | has 'temp_low' => ( is => 'ro', isa => 'Weather::Bug::Temperature', init_arg => '-temp_low' ); | |||||||||||||||||||||||||||
| 59 | 12 | has 'temp_rate' => ( is => 'ro', isa => 'Weather::Bug::Temperature', init_arg => '-temp_rate' ); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 12 | has 'sunrise' => ( is => 'ro', isa => 'DateTime', init_arg => '-sunrise' ); | |||||||||||||||||||||||||||
| 62 | 12 | has 'sunset' => ( is => 'ro', isa => 'DateTime', init_arg => '-sunset' ); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 12 | has 'wet_bulb' => ( is => 'ro', isa => 'Weather::Bug::Temperature', init_arg => '-wetbulb' ); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 12 | has 'wind_speed' => ( is => 'ro', isa => 'Weather::Bug::Quantity', init_arg => '-wind_speed' ); | |||||||||||||||||||||||||||
| 67 | 12 | has 'wind_speed_avg' => ( is => 'ro', isa => 'Weather::Bug::Quantity', init_arg => '-wind_speed_avg' ); | |||||||||||||||||||||||||||
| 68 | 12 | has 'wind_dir' => ( is => 'ro', isa => 'Str', init_arg => '-wind_dir' ); | |||||||||||||||||||||||||||
| 69 | 12 | has 'wind_dir_avg' => ( is => 'ro', isa => 'Str', init_arg => '-wind_dir_avg' ); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub _parse_datetime | ||||||||||||||||||||||||||||
| 72 | 8 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_parse_datetime: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||
| 73 | 8 | my $node = shift; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 8 | my $tz = $node->findvalue( 'aws:time-zone/@offset' ); | |||||||||||||||||||||||||||
| 76 | 8 | ▶ | if( length $tz ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||
| 78 | 4 | ▶ | $tz *= 100 if -30 < $tz && $tz < 30; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-30 < $tz and $tz < 30
MC/DC0%0/2
-30 < $tz and $tz < 30
-30 < $tz
$tz < 30
Truth table33%1/3
A and B
A= -30 < $tzB= $tz < 30
| |||||||||||||||||||||||||||||
| 79 | 4 | $tz = sprintf '%+05d', $tz; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | else | ||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||
| 83 | 4 | $tz = "floating"; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 8 | return DateTime->new( | |||||||||||||||||||||||||||
| 87 | year => $node->findvalue( 'aws:year/@number' ), | ||||||||||||||||||||||||||||
| 88 | month => $node->findvalue( 'aws:month/@number' ), | ||||||||||||||||||||||||||||
| 89 | day => $node->findvalue( 'aws:day/@number' ), | ||||||||||||||||||||||||||||
| 90 | hour => $node->findvalue( 'aws:hour/@hour-24' ), | ||||||||||||||||||||||||||||
| 91 | minute => $node->findvalue( 'aws:minute/@number' ), | ||||||||||||||||||||||||||||
| 92 | second => $node->findvalue( 'aws:second/@number' ), | ||||||||||||||||||||||||||||
| 93 | time_zone => $tz, | ||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | sub from_xml | ||||||||||||||||||||||||||||
| 98 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
from_xml: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 100 | 2 | my $w = shift; | |||||||||||||||||||||||||||
| 101 | 2 | my $creator = shift; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 2 | ▶ | if( $creator->isa( 'Weather::Bug' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 1 | $creator = Weather::Bug::Station->from_obs_xml( $creator, $w ); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 2 | ▶ | die "Unable to create a Station localizing the Weather.\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | unless $creator->isa( 'Weather::Bug::Station' ); | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 2 | return Weather::Bug::Weather->new( | |||||||||||||||||||||||||||
| 110 | -date => _parse_datetime( ($w->findnodes( 'aws:ob-date' ))[0] ), | ||||||||||||||||||||||||||||
| 111 | -station => $creator, | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | -aux_temp => Weather::Bug::Temperature->from_xml( ($w->findnodes( 'aws:aux-temp' ))[0] ), | ||||||||||||||||||||||||||||
| 114 | -aux_rate => Weather::Bug::Temperature->from_xml( ($w->findnodes( 'aws:aux-temp-rate' ))[0] ), | ||||||||||||||||||||||||||||
| 115 | -dewpt => Weather::Bug::Temperature->from_xml( ($w->findnodes( 'aws:dew-point' ))[0] ), | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | -elevation => Weather::Bug::Quantity->from_xml( ($w->findnodes( 'aws:elevation' ))[0] ), | ||||||||||||||||||||||||||||
| 118 | -feels => Weather::Bug::Temperature->from_xml( ($w->findnodes( 'aws:feels-like' ))[0] ), | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | -gust_time => _parse_datetime( ($w->findnodes( 'aws:gust-time' ))[0] ), | ||||||||||||||||||||||||||||
| 121 | -gust_speed => Weather::Bug::Quantity->from_xml( ($w->findnodes( 'aws:gust-speed' ))[0] ), | ||||||||||||||||||||||||||||
| 122 | -gust_dir => $w->findvalue( 'aws:gust-direction' ), | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | -humidity => Weather::Bug::Quantity->from_xml( ($w->findnodes( 'aws:humidity' ))[0] ), | ||||||||||||||||||||||||||||
| 125 | -humidity_high => Weather::Bug::Quantity->from_xml( ($w->findnodes( 'aws:humidity-high' ))[0] ), | ||||||||||||||||||||||||||||
| 126 | -humidity_low => Weather::Bug::Quantity->from_xml( ($w->findnodes( 'aws:humidity-low' ))[0] ), | ||||||||||||||||||||||||||||
| 127 | -humidity_rate => $w->findvalue( 'aws:humidity-rate' ), | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | -indoor_temp => Weather::Bug::Temperature->from_xml( ($w->findnodes( 'aws:indoor-temp' ))[0] ), | ||||||||||||||||||||||||||||
| 130 | -indoor_temp_rate => Weather::Bug::Temperature->from_xml( ($w->findnodes( 'aws:indoor-temp-rate' ))[0] ), | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | -light => $w->findvalue( 'aws:light' ), | ||||||||||||||||||||||||||||
| 133 | -light_rate => $w->findvalue( 'aws:light-rate' ), | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | -moon_phase => $w->findvalue( 'aws:moon-phase' ), | ||||||||||||||||||||||||||||
| 136 | -moon_phase_img => $w->findvalue( 'aws:moon-phase/@moon-phase-img' ), | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | -pressure => Weather::Bug::Quantity->from_xml( ($w->findnodes( 'aws:pressure' ))[0] ), | ||||||||||||||||||||||||||||
| 139 | -pressure_high => Weather::Bug::Quantity->from_xml( ($w->findnodes( 'aws:pressure-high' ))[0] ), | ||||||||||||||||||||||||||||
| 140 | -pressure_low => Weather::Bug::Quantity->from_xml( ($w->findnodes( 'aws:pressure-low' ))[0] ), | ||||||||||||||||||||||||||||
| 141 | -pressure_rate => $w->findvalue( 'aws:pressure-rate' ), | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | -rain_month => Weather::Bug::Quantity->from_xml( ($w->findnodes( 'aws:rain-month' ))[0] ), | ||||||||||||||||||||||||||||
| 144 | -rain_rate => Weather::Bug::Quantity->from_xml( ($w->findnodes( 'aws:rain-rate' ))[0] ), | ||||||||||||||||||||||||||||
| 145 | -rain_rate_max => Weather::Bug::Quantity->from_xml( ($w->findnodes( 'aws:rain-rate-max' ))[0] ), | ||||||||||||||||||||||||||||
| 146 | -rain_today => Weather::Bug::Quantity->from_xml( ($w->findnodes( 'aws:rain-today' ))[0] ), | ||||||||||||||||||||||||||||
| 147 | -rain_year => Weather::Bug::Quantity->from_xml( ($w->findnodes( 'aws:rain-year' ))[0] ), | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | -temp => Weather::Bug::Temperature->from_xml( ($w->findnodes( 'aws:temp' ))[0] ), | ||||||||||||||||||||||||||||
| 150 | -temp_high => Weather::Bug::Temperature->from_xml( ($w->findnodes( 'aws:temp-high' ))[0] ), | ||||||||||||||||||||||||||||
| 151 | -temp_low => Weather::Bug::Temperature->from_xml( ($w->findnodes( 'aws:temp-low' ))[0] ), | ||||||||||||||||||||||||||||
| 152 | -temp_rate => Weather::Bug::Temperature->from_xml( ($w->findnodes( 'aws:temp-rate' ))[0] ), | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | -sunrise => _parse_datetime( ($w->findnodes( 'aws:sunrise' ))[0] ), | ||||||||||||||||||||||||||||
| 155 | -sunset => _parse_datetime( ($w->findnodes( 'aws:sunset' ))[0] ), | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | -wetbulb => Weather::Bug::Temperature->from_xml( ($w->findnodes( 'aws:wet-bulb' ))[0] ), | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | -wind_speed => Weather::Bug::Quantity->from_xml( ($w->findnodes( 'aws:wind-speed' ))[0] ), | ||||||||||||||||||||||||||||
| 160 | -wind_speed_avg => Weather::Bug::Quantity->from_xml( ($w->findnodes( 'aws:wind-speed-avg' ))[0] ), | ||||||||||||||||||||||||||||
| 161 | -wind_dir => $w->findvalue( 'aws:wind-direction' ), | ||||||||||||||||||||||||||||
| 162 | -wind_dir_avg => $w->findvalue( 'aws:wind-direction-avg' ), | ||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 12 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||
| 167 | __END__ | ||||||||||||||||||||||||||||