OpenWeatherMap/Result/Current.pm

filter: Statementstmt 98.9% 90 / 91 Branchbran 66.6% 4 / 6 Conditioncond 47.3% 18 / 38 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 97.1% 34 / 35 Podpod 0.0% 0 / 1 totaltotal 76.4% 146 / 191 CC 27 SCAR 7.7
CC
27
Cov
83%
_build_wind_gust_mph
4.8
_so_weather_maybe
3.3
_build_conditions_terse
3.2
CRAP 2.1
« OpenWeatherMap/Error.pm ↑ Summary OpenWeatherMap/Request.pm »
1 package Weather::OpenWeatherMap::Result::Current;
2 2 $Weather::OpenWeatherMap::Result::Current::VERSION = '0.005001';
3 2 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use List::Objects::Types -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Types::Standard -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Types::DateTime -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 use Weather::OpenWeatherMap::Units qw/
11 f_to_c
12 mph_to_kph
13 deg_to_compass
14 2 ▶/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 =pod
18  
19 =for Pod::Coverage lazy_for
20  
21 =cut
22  
23 sub lazy_for {
24 48 ▶ my $type = shift;
Subroutine lazy_for: called CC=2 SCAR=6.9
Pod undocumented
25 (
26 48 ▶ lazy => 1, is => 'ro', isa => $type,
Branch: 1 branch
BranchTrueFalseTotal
$type->has_coercion ? : 6 42 48
27 ( $type->has_coercion ? (coerce => 1) : () ),
28 @_
29 )
30 }
31  
32  
33 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 extends 'Weather::OpenWeatherMap::Result';
35  
36  
37 has dt => ( lazy_for DateTimeUTC,
38 6 ▶ builder => sub { shift->data->{dt} },
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine _build_dt: called CC=1 SCAR=0.0
39 2 );
40  
41 has id => ( lazy_for Int,
42 2 ▶ builder => sub { shift->data->{id} },
Subroutine _build_id: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=1 SCAR=1.2
43 2 );
44  
45 has name => ( lazy_for Str,
46 8 ▶ builder => sub { shift->data->{name} },
Subroutine __ANON__: called CC=1 SCAR=0.0
47 2 );
48  
49 has country => ( lazy_for Str,
50 8 ▶ builder => sub { shift->data->{sys}->{country} // '' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
+(shift())->data->{"sys"}{"country"} // ""
l!l
80
MC/DC0%0/1
+(shift())->data->{"sys"}{"country"} // ""
+(shift())->data->{"sys"}{"country"}
Truth table50%1/2
A
A= +(shift())->data->{"sys"}{"country"}
Aresult
11
00
51 2 );
52  
53 has station => ( lazy_for Str,
54 2 ▶ builder => sub { shift->data->{base} // '' },
Subroutine _build_station: called CC=2 SCAR=7.6
Condition50%1/2
+(shift())->data->{"base"} // ""
l!l
20
MC/DC0%0/1
+(shift())->data->{"base"} // ""
+(shift())->data->{"base"}
Truth table50%1/2
A
A= +(shift())->data->{"base"}
Aresult
11
00
55 2 );
56  
57  
58 has latitude => ( lazy_for StrictNum,
59 2 ▶ builder => sub { shift->data->{coord}->{lat} },
Subroutine _build_latitude: called CC=1 SCAR=0.0
60 2 );
61  
62 has longitude => ( lazy_for StrictNum,
63 2 ▶ builder => sub { shift->data->{coord}->{lon} },
Subroutine __ANON__: called CC=1 SCAR=0.0
64 2 );
65  
66  
67 has temp_f => ( lazy_for Int,
68 2 ▶ builder => sub { int( shift->data->{main}->{temp} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
69 2 );
70  
71 has temp_c => ( lazy_for Int,
72 2 ▶ builder => sub { int f_to_c( shift->temp_f ) },
Subroutine _build_temp_c: called CC=1 SCAR=0.0
73 2 );
74  
75  
76 has humidity => ( lazy_for Int,
77 2 ▶ builder => sub { int( shift->data->{main}->{humidity} // 0 ) },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
+(shift())->data->{"main"}{"humidity"} // 0
l!l
20
MC/DC0%0/1
+(shift())->data->{"main"}{"humidity"} // 0
+(shift())->data->{"main"}{"humidity"}
Truth table50%1/2
A
A= +(shift())->data->{"main"}{"humidity"}
Aresult
11
00
78 2 );
79  
80 has pressure => ( lazy_for StrictNum,
81 2 ▶ builder => sub { shift->data->{main}->{pressure} },
Subroutine _build_pressure: called CC=1 SCAR=0.0
82 2 );
83  
84 has cloud_coverage => ( lazy_for Int,
85 2 ▶ builder => sub { int( shift->data->{clouds}->{all} // 0 ) },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
+(shift())->data->{"clouds"}{"all"} // 0
l!l
20
MC/DC0%0/1
+(shift())->data->{"clouds"}{"all"} // 0
+(shift())->data->{"clouds"}{"all"}
Truth table50%1/2
A
A= +(shift())->data->{"clouds"}{"all"}
Aresult
11
00
86 2 );
87  
88  
89 has sunrise => ( lazy_for DateTimeUTC,
90 2 ▶ builder => sub { shift->data->{sys}->{sunrise} // 0 },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
+(shift())->data->{"sys"}{"sunrise"} // 0
l!l
20
MC/DC0%0/1
+(shift())->data->{"sys"}{"sunrise"} // 0
+(shift())->data->{"sys"}{"sunrise"}
Truth table50%1/2
A
A= +(shift())->data->{"sys"}{"sunrise"}
Aresult
11
00
91 2 );
92  
93 has sunset => ( lazy_for DateTimeUTC,
94 2 ▶ builder => sub { shift->data->{sys}->{sunset} // 0 },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
+(shift())->data->{"sys"}{"sunset"} // 0
l!l
20
MC/DC0%0/1
+(shift())->data->{"sys"}{"sunset"} // 0
+(shift())->data->{"sys"}{"sunset"}
Truth table50%1/2
A
A= +(shift())->data->{"sys"}{"sunset"}
Aresult
11
00
95 2 );
96  
97  
98 sub _so_weather_maybe {
99 8 ▶ my ($self) = @_;
Subroutine _so_weather_maybe: called CC=3 SCAR=12.0
100 8 my $weather = $self->data->{weather};
101 8 ▶ return unless ref $weather eq 'ARRAY' and @$weather;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $weather eq "ARRAY" and @$weather 0 8 8
Condition33%1/3
ref $weather eq "ARRAY" and @$weather
!ll&&!rl&&r
008
MC/DC0%0/2
ref $weather eq "ARRAY" and @$weather
ref $weather eq "ARRAY" @$weather
Truth table33%1/3
A and B
A= ref $weather eq "ARRAY"B= @$weather
ABresult
0X0
100
111
102 8 $weather->[0]
103 }
104  
105 has conditions_terse => ( lazy_for Str,
106 builder => sub {
107 2 ▶ my ($self) = @_;
Subroutine _build_conditions_terse: called CC=3 SCAR=11.7
108 2 ▶ my $weather = $self->_so_weather_maybe || return '';
Condition50%1/2
$self->_so_weather_maybe || (return '')
l!l
20
MC/DC0%0/1
$self->_so_weather_maybe || (return '')
$self->_so_weather_maybe
Truth table50%1/2
A
A= $self->_so_weather_maybe
Aresult
11
00
109 2 ▶ $weather->{main} // ''
Condition50%1/2
$weather->{"main"} // ""
l!l
20
MC/DC0%0/1
$weather->{"main"} // ""
$weather->{"main"}
Truth table50%1/2
A
A= $weather->{"main"}
Aresult
11
00
110 },
111 2 );
112  
113 has conditions_verbose => ( lazy_for Str,
114 builder => sub {
115 2 ▶ my ($self) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.7
116 2 ▶ my $weather = $self->_so_weather_maybe || return '';
Condition50%1/2
$self->_so_weather_maybe || (return '')
l!l
20
MC/DC0%0/1
$self->_so_weather_maybe || (return '')
$self->_so_weather_maybe
Truth table50%1/2
A
A= $self->_so_weather_maybe
Aresult
11
00
117 2 ▶ $weather->{description} // ''
Condition50%1/2
$weather->{"description"} // ""
l!l
20
MC/DC0%0/1
$weather->{"description"} // ""
$weather->{"description"}
Truth table50%1/2
A
A= $weather->{"description"}
Aresult
11
00
118 },
119 2 );
120  
121 has conditions_code => ( lazy_for Int,
122 builder => sub {
123 2 ▶ my ($self) = @_;
Subroutine _build_conditions_code: called CC=3 SCAR=11.7
124 2 ▶ my $weather = $self->_so_weather_maybe || return 0;
Condition50%1/2
$self->_so_weather_maybe || (return 0)
l!l
20
MC/DC0%0/1
$self->_so_weather_maybe || (return 0)
$self->_so_weather_maybe
Truth table50%1/2
A
A= $self->_so_weather_maybe
Aresult
11
00
125 2 ▶ $weather->{id} // 0
Condition50%1/2
$weather->{"id"} // 0
l!l
20
MC/DC0%0/1
$weather->{"id"} // 0
$weather->{"id"}
Truth table50%1/2
A
A= $weather->{"id"}
Aresult
11
00
126 },
127 2 );
128  
129 has conditions_icon => ( lazy_for Maybe[Str],
130 builder => sub {
131 2 ▶ my ($self) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.1
132 2 ▶ my $weather = $self->_so_weather_maybe || return;
Condition50%1/2
$self->_so_weather_maybe || (return)
l!l
20
MC/DC0%0/1
$self->_so_weather_maybe || (return)
$self->_so_weather_maybe
Truth table50%1/2
A
A= $self->_so_weather_maybe
Aresult
11
00
133 $weather->{icon}
134 2 },
135 2 );
136  
137  
138 has wind_speed_mph => ( lazy_for Int,
139 2 ▶ builder => sub { int( shift->data->{wind}->{speed} // 0 ) },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
+(shift())->data->{"wind"}{"speed"} // 0
l!l
20
MC/DC0%0/1
+(shift())->data->{"wind"}{"speed"} // 0
+(shift())->data->{"wind"}{"speed"}
Truth table50%1/2
A
A= +(shift())->data->{"wind"}{"speed"}
Aresult
11
00
140 2 );
141  
142 has wind_speed_kph => ( lazy_for Int,
143 2 ▶ builder => sub { int( mph_to_kph shift->wind_speed_mph ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
144 2 );
145  
146 has wind_direction_degrees => ( lazy_for StrictNum,
147 2 ▶ builder => sub { shift->data->{wind}->{deg} // 0 },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
+(shift())->data->{"wind"}{"deg"} // 0
l!l
20
MC/DC0%0/1
+(shift())->data->{"wind"}{"deg"} // 0
+(shift())->data->{"wind"}{"deg"}
Truth table50%1/2
A
A= +(shift())->data->{"wind"}{"deg"}
Aresult
11
00
148 2 );
149  
150 has wind_direction => ( lazy_for Str,
151 2 ▶ builder => sub { deg_to_compass( shift->wind_direction_degrees ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
152 2 );
153  
154 has wind_gust_mph => ( lazy_for Int,
155 builder => sub {
156 2 ▶ my ($self) = @_;
Subroutine _build_wind_gust_mph: called CC=4 SCAR=15.6
157 2 ▶ my $gust = int( $self->data->{wind}->{gust} // 0 );
Condition50%1/2
$self->data->{"wind"}{"gust"} // 0
l!l
20
MC/DC0%0/1
$self->data->{"wind"}{"gust"} // 0
$self->data->{"wind"}{"gust"}
Truth table50%1/2
A
A= $self->data->{"wind"}{"gust"}
Aresult
11
00
158 2 ▶ return 0 unless $gust and $gust > $self->wind_speed_mph;
Branch: 1 branch
BranchTrueFalseTotal
unless $gust and $gust > $self->wind_speed_mph 0 2 2
Condition33%1/3
$gust and $gust > $self->wind_speed_mph
!ll&&!rl&&r
002
MC/DC0%0/2
$gust and $gust > $self->wind_speed_mph
$gust $gust > $self->wind_speed_mph
Truth table33%1/3
A and B
A= $gustB= $gust > $self->wind_speed_mph
ABresult
0X0
100
111
159 2 $gust
160 },
161 2 );
162  
163 has wind_gust_kph => ( lazy_for Int,
164 2 ▶ builder => sub { int( mph_to_kph shift->wind_gust_mph ) },
Subroutine _build_wind_gust_kph: called CC=1 SCAR=0.0
165 2 );
166  
167 2 1;
168  
169 =pod
170  
171 =head1 NAME
172  
173 Weather::OpenWeatherMap::Result::Current - Weather conditions result
174  
175 =head1 SYNOPSIS
176  
177 # Normally retrieved via Weather::OpenWeatherMap
178  
179 =head1 DESCRIPTION
180  
181 This is a subclass of L<Weather::OpenWeatherMap::Result> containing the
182 result of a completed L<Weather::OpenWeatherMap::Request::Current>.
183  
184 These are normally emitted by a L<Weather::OpenWeatherMap> instance.
185  
186 =head2 ATTRIBUTES
187  
188 =head3 Station
189  
190 =head4 country
191  
192 The country string.
193  
194 =head4 dt
195  
196 my $reported_at = $result->dt->hms;
197  
198 A UTC L<DateTime> object representing the time this report was updated.
199  
200 =head4 id
201  
202 The L<OpenWeatherMap|http://www.openweathermap.org/> city code.
203  
204 =head4 latitude
205  
206 The station's latitude.
207  
208 =head4 longitude
209  
210 The station's longitude.
211  
212 =head4 name
213  
214 The returned city name.
215  
216 =head4 station
217  
218 The returned station name.
219  
220 =head3 Conditions
221  
222 =head4 cloud_coverage
223  
224 The cloud coverage as a percentage.
225  
226 =head4 conditions_code
227  
228 The L<OpenWeatherMap|http://www.openweathermap.org/> conditions code.[
229  
230 =head4 conditions_icon
231  
232 The L<OpenWeatherMap|http://www.openweathermap.org/> conditions icon.
233  
234 =head4 conditions_terse
235  
236 The conditions category.
237  
238 =head4 conditions_verbose
239  
240 The conditions description string.
241  
242 =head4 humidity
243  
244 Current humidity.
245  
246 =head4 pressure
247  
248 Atmospheric pressure in hPa.
249  
250 =head4 sunrise
251  
252 A UTC L<DateTime> object representing sunrise time.
253  
254 (Not available for L<Weather::OpenWeatherMap::Result::Find> result items.)
255  
256 =head4 sunset
257  
258 A UTC L<DateTime> object representing sunset time.
259  
260 (Not available for L<Weather::OpenWeatherMap::Result::Find> result items.)
261  
262 =head3 Temperature
263  
264 =head4 temp_f
265  
266 Temperature in degrees Fahrenheit.
267  
268 =head4 temp_c
269  
270 Temperature in degrees Celsius.
271  
272 =head3 Wind
273  
274 =head4 wind_speed_mph
275  
276 Wind speed in MPH.
277  
278 =head4 wind_speed_kph
279  
280 Wind speed in KPH.
281  
282 =head4 wind_gust_mph
283  
284 Wind gust speed in MPH (or 0 if the gust speed matches L</wind_speed_mph> or
285 is unavailable)
286  
287 =head4 wind_gust_kph
288  
289 Wind gust speed in KPH (or 0 if the gust speed matches L</wind_speed_kph> or
290 is unavailable)
291  
292 =head4 wind_direction
293  
294 The wind direction, as a (inter-)cardinal direction in the set
295 C<< [ N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW ] >>
296  
297 =head4 wind_direction_degrees
298  
299 The wind direction, in degrees azimuth.
300  
301 =head1 SEE ALSO
302  
303 L<http://www.openweathermap.org/current>
304  
305 L<Weather::OpenWeatherMap::Result>
306  
307 L<Weather::OpenWeatherMap::Result::Forecast>
308  
309 L<Weather::OpenWeatherMap::Request>
310  
311 =head1 AUTHOR
312  
313 Jon Portnoy <avenj@cobaltirc.org>
314  
315 Licensed under the same terms as Perl.
316  
317 =cut
« OpenWeatherMap/Error.pm ↑ Summary OpenWeatherMap/Request.pm »