| 1 | package Weather::Com::CurrentConditions; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use Weather::Com::AirPressure; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Weather::Com::DateTime; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use Weather::Com::Moon; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use Weather::Com::UVIndex; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use Weather::Com::Wind; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use Weather::Com::L10N; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | ▶ | use base "Weather::Com::Cached"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 1 | our $VERSION = sprintf "%d.%03d", q$Revision: 1.14 $ =~ /(\d+)/g; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | #------------------------------------------------------------------------ | ||||||||||||||||||||
| 17 | # Constructor | ||||||||||||||||||||
| 18 | #------------------------------------------------------------------------ | ||||||||||||||||||||
| 19 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 20 | 0 | my $proto = shift; | |||||||||||||||||||
| 21 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 22 | 0 | my %parameters; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | # parameters provided by new method | ||||||||||||||||||||
| 25 | 0 | ▶ | if ( ref( $_[0] ) eq "HASH" ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 0 | %parameters = %{ $_[0] }; | |||||||||||||||||||
| 27 | } else { | ||||||||||||||||||||
| 28 | 0 | %parameters = @_; | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | ▶ | unless ( $parameters{location_id} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 0 | die "You need to provide a location id!\n"; | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | # set some parameters to sensible values for a | ||||||||||||||||||||
| 36 | # current conditions object | ||||||||||||||||||||
| 37 | 0 | $parameters{current} = 1; | |||||||||||||||||||
| 38 | 0 | $parameters{forecast} = 0; | |||||||||||||||||||
| 39 | 0 | $parameters{links} = 0; | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | # creating the SUPER instance | ||||||||||||||||||||
| 42 | 0 | my $self = $class->SUPER::new( \%parameters ); | |||||||||||||||||||
| 43 | 0 | $self->{ID} = $parameters{location_id}; | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | # getting first weather information | ||||||||||||||||||||
| 46 | 0 | $self->{BAR} = undef; | |||||||||||||||||||
| 47 | 0 | $self->{UV} = undef; | |||||||||||||||||||
| 48 | 0 | $self->{MOON} = undef; | |||||||||||||||||||
| 49 | 0 | $self->{WEATHER} = $self->get_weather( $self->{ID} ); | |||||||||||||||||||
| 50 | 0 | $self->{WIND} = undef; | |||||||||||||||||||
| 51 | 0 | $self->{LAST_XML_UPDATE} = undef; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | # remember instantiation time (and later last update time) | ||||||||||||||||||||
| 54 | 0 | $self->{LSUP} = time(); | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 0 | return $self; | |||||||||||||||||||
| 57 | } # end new() | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | #------------------------------------------------------------------------ | ||||||||||||||||||||
| 60 | # refresh weather data | ||||||||||||||||||||
| 61 | #------------------------------------------------------------------------ | ||||||||||||||||||||
| 62 | 0 | ▶ | sub refresh { | ||||||||||||||||||
|
Subroutine
refresh: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 63 | 0 | my $self = shift; | |||||||||||||||||||
| 64 | 0 | my $now = time(); | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | # only refresh if last update has been more than 15 min ago | ||||||||||||||||||||
| 67 | 0 | ▶ | if ( ( $now - $self->{LSUP} ) > 900 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | 0 | $self->{WEATHER} = $self->get_weather( $self->{ID} ); | |||||||||||||||||||
| 69 | 0 | $self->{LSUP} = $now; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | 0 | return 1; | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | #------------------------------------------------------------------------ | ||||||||||||||||||||
| 75 | # access location data | ||||||||||||||||||||
| 76 | #------------------------------------------------------------------------ | ||||||||||||||||||||
| 77 | 0 | ▶ | sub id { | ||||||||||||||||||
|
Subroutine
id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 78 | 0 | my $self = shift; | |||||||||||||||||||
| 79 | 0 | return $self->{ID}; | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 0 | ▶ | sub name { | ||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 83 | 0 | my $self = shift; | |||||||||||||||||||
| 84 | 0 | $self->refresh(); | |||||||||||||||||||
| 85 | 0 | return $self->{WEATHER}->{loc}->{dnam}; | |||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | ▶ | sub icon { | ||||||||||||||||||
|
Subroutine
icon: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 89 | 0 | my $self = shift; | |||||||||||||||||||
| 90 | 0 | return $self->{WEATHER}->{cc}->{icon}; | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | ▶ | sub description { | ||||||||||||||||||
|
Subroutine
description: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 94 | 0 | my $self = shift; | |||||||||||||||||||
| 95 | 0 | my $language = shift; | |||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 0 | $self->refresh(); | |||||||||||||||||||
| 98 | return $self->get_language_handle($language) | ||||||||||||||||||||
| 99 | 0 | ->maketext( lc( $self->{WEATHER}->{cc}->{t} ) ); | |||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 0 | ▶ | sub temperature { | ||||||||||||||||||
|
Subroutine
temperature: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 104 | 0 | my $self = shift; | |||||||||||||||||||
| 105 | 0 | $self->refresh(); | |||||||||||||||||||
| 106 | 0 | return $self->{WEATHER}->{cc}->{tmp}; | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 0 | ▶ | sub windchill { | ||||||||||||||||||
|
Subroutine
windchill: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 110 | 0 | my $self = shift; | |||||||||||||||||||
| 111 | 0 | $self->refresh(); | |||||||||||||||||||
| 112 | 0 | return $self->{WEATHER}->{cc}->{flik}; | |||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 0 | ▶ | sub humidity { | ||||||||||||||||||
|
Subroutine
humidity: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 116 | 0 | my $self = shift; | |||||||||||||||||||
| 117 | 0 | $self->refresh(); | |||||||||||||||||||
| 118 | 0 | return $self->{WEATHER}->{cc}->{hmid}; | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 0 | ▶ | sub pressure { | ||||||||||||||||||
|
Subroutine
pressure: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 122 | 0 | my $self = shift; | |||||||||||||||||||
| 123 | 0 | $self->refresh(); | |||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 0 | ▶ | unless ( $self->{BAR} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 126 | 0 | $self->{BAR} = Weather::Com::AirPressure->new( $self->{ARGS} ); | |||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | 0 | $self->{BAR}->update( $self->{WEATHER}->{cc}->{bar} ); | |||||||||||||||||||
| 129 | 0 | return $self->{BAR}; | |||||||||||||||||||
| 130 | } | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 0 | ▶ | sub dewpoint { | ||||||||||||||||||
|
Subroutine
dewpoint: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 133 | 0 | my $self = shift; | |||||||||||||||||||
| 134 | 0 | $self->refresh(); | |||||||||||||||||||
| 135 | 0 | return $self->{WEATHER}->{cc}->{dewp}; | |||||||||||||||||||
| 136 | } | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 0 | ▶ | sub moon { | ||||||||||||||||||
|
Subroutine
moon: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 139 | 0 | my $self = shift; | |||||||||||||||||||
| 140 | 0 | $self->refresh(); | |||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | 0 | ▶ | unless ( $self->{MOON} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 143 | 0 | $self->{MOON} = Weather::Com::Moon->new( $self->{ARGS} ); | |||||||||||||||||||
| 144 | } | ||||||||||||||||||||
| 145 | 0 | $self->{MOON}->update( $self->{WEATHER}->{cc}->{moon} ); | |||||||||||||||||||
| 146 | 0 | return $self->{MOON}; | |||||||||||||||||||
| 147 | } | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | 0 | ▶ | sub uv_index { | ||||||||||||||||||
|
Subroutine
uv_index: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 150 | 0 | my $self = shift; | |||||||||||||||||||
| 151 | 0 | $self->refresh(); | |||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 0 | ▶ | unless ( $self->{UV} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 154 | 0 | $self->{UV} = Weather::Com::UVIndex->new( $self->{ARGS} ); | |||||||||||||||||||
| 155 | } | ||||||||||||||||||||
| 156 | 0 | $self->{UV}->update( $self->{WEATHER}->{cc}->{uv} ); | |||||||||||||||||||
| 157 | 0 | return $self->{UV}; | |||||||||||||||||||
| 158 | } | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | 0 | ▶ | sub visibility { | ||||||||||||||||||
|
Subroutine
visibility: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 161 | 0 | my $self = shift; | |||||||||||||||||||
| 162 | 0 | $self->refresh(); | |||||||||||||||||||
| 163 | 0 | return $self->{WEATHER}->{cc}->{vis}; | |||||||||||||||||||
| 164 | } | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | 0 | ▶ | sub wind { | ||||||||||||||||||
|
Subroutine
wind: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 167 | 0 | my $self = shift; | |||||||||||||||||||
| 168 | 0 | $self->refresh(); | |||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | 0 | ▶ | unless ( $self->{WIND} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 171 | 0 | $self->{WIND} = Weather::Com::Wind->new( $self->{ARGS} ); | |||||||||||||||||||
| 172 | } | ||||||||||||||||||||
| 173 | 0 | $self->{WIND}->update( $self->{WEATHER}->{cc}->{wind} ); | |||||||||||||||||||
| 174 | 0 | return $self->{WIND}; | |||||||||||||||||||
| 175 | } | ||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | 0 | ▶ | sub observatory { | ||||||||||||||||||
|
Subroutine
observatory: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 178 | 0 | my $self = shift; | |||||||||||||||||||
| 179 | 0 | $self->refresh(); | |||||||||||||||||||
| 180 | 0 | return $self->{WEATHER}->{cc}->{obst}; | |||||||||||||||||||
| 181 | } | ||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | 0 | ▶ | sub last_updated { | ||||||||||||||||||
|
Subroutine
last_updated: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 184 | 0 | my $self = shift; | |||||||||||||||||||
| 185 | 0 | $self->refresh(); | |||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | 0 | ▶ | unless ( $self->{LAST_XML_UPDATE} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 188 | $self->{LAST_XML_UPDATE} = | ||||||||||||||||||||
| 189 | 0 | Weather::Com::DateTime->new( $self->{ARGS}->{zone} ); | |||||||||||||||||||
| 190 | } | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | 0 | $self->{LAST_XML_UPDATE}->set_lsup( $self->{WEATHER}->{cc}->{lsup} ); | |||||||||||||||||||
| 193 | 0 | return $self->{LAST_XML_UPDATE}; | |||||||||||||||||||
| 194 | } | ||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | 1 | 1; | |||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | __END__ | ||||||||||||||||||||