YR/LocationForecast/Day.pm

filter: Statementstmt 21.2% 27 / 127 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 9.5% 2 / 21 Podpod n/a totaltotal 16.2% 29 / 179 CC 25 SCAR 24.1
CC
25
Cov
17%
_ok_hour
20.0
_build_precipitations
20.0
_build_temperature
12.0
CRAP 11.2
↑ Summary YR/Base.pm »
1 package Weather::YR::LocationForecast::Day;
2 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 extends 'Weather::YR::Day';
6  
7 =head1 NAME
8  
9 Weather::YR::LocationForecast::Day - Class that holds weather data for one day.
10  
11 =head1 DESCRIPTION
12  
13 Don't use this class directly. Instead, access it via L<Weather::YR> and
14 L<Weather::YR::LocationForecast>.
15  
16 =cut
17  
18 # Temperature
19 3 has 'temperatures' => ( isa => 'ArrayRef[Weather::YR::Model::Temperature]', is => 'ro', lazy_build => 1 );
20 3 has 'temperature' => ( isa => 'Weather::YR::Model::Temperature', is => 'ro', lazy_build => 1 );
21  
22 # Precipitation
23 3 has 'precipitations' => ( isa => 'ArrayRef[Weather::YR::Model::Precipitation]', is => 'ro', lazy_build => 1 );
24 3 has 'precipitation' => ( isa => 'Weather::YR::Model::Precipitation', is => 'ro', lazy_build => 1 );
25  
26 # Wind direction
27 3 has 'wind_directions' => ( isa => 'ArrayRef[Weather::YR::Model::WindDirection]', is => 'ro', lazy_build => 1 );
28 3 has 'wind_direction' => ( isa => 'Weather::YR::Model::WindDirection', is => 'ro', lazy_build => 1 );
29  
30 # Wind speed
31 3 has 'wind_speeds' => ( isa => 'ArrayRef[Weather::YR::Model::WindSpeed]', is => 'ro', lazy_build => 1 );
32 3 has 'wind_speed' => ( isa => 'Weather::YR::Model::WindSpeed', is => 'ro', lazy_build => 1 );
33  
34 # Humidity
35 3 has 'humidities' => ( isa => 'ArrayRef[Weather::YR::Model::Humidity]', is => 'ro', lazy_build => 1 );
36 3 has 'humidity' => ( isa => 'Weather::YR::Model::Humidity', is => 'ro', lazy_build => 1 );
37  
38 # Pressure
39 3 has 'pressures' => ( isa => 'ArrayRef[Weather::YR::Model::Pressure]', is => 'ro', lazy_build => 1 );
40 3 has 'pressure' => ( isa => 'Weather::YR::Model::Pressure', is => 'ro', lazy_build => 1 );
41  
42 # Cloudiness
43 3 has 'cloudinesses' => ( isa => 'ArrayRef[Weather::YR::Model::Cloudiness]', is => 'ro', lazy_build => 1 );
44 3 has 'cloudiness' => ( isa => 'Weather::YR::Model::Cloudiness', is => 'ro', lazy_build => 1 );
45  
46 # Fog
47 3 has 'fogs' => ( isa => 'ArrayRef[Weather::YR::Model::Fog]', is => 'ro', lazy_build => 1 );
48 3 has 'fog' => ( isa => 'Weather::YR::Model::Fog', is => 'ro', lazy_build => 1 );
49  
50 # Dew point temperature
51 3 has 'dew_point_temperatures' => ( isa => 'ArrayRef[Weather::YR::Model::DewPointTemperature]', is => 'ro', lazy_build => 1 );
52 3 has 'dew_point_temperature' => ( isa => 'Weather::YR::Model::DewPointTemperature', is => 'ro', lazy_build => 1 );
53  
54 =head1 METHODS
55  
56 This class inherits all the methods from L<Weather::YR::Day> and provides the
57 following new methods:
58  
59 =cut
60  
61 sub _ok_hour {
62 0 ▶ my $self = shift;
Subroutine _ok_hour: not called CC=4 SCAR=30.0
63 0 my $hour = shift;
64  
65 0 ▶ if ( defined $hour && ($hour >= 12 && $hour <= 15) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hour and ($hour >= 12 and $hour <= 15)) { } 0 0 0
Condition0%0/6
defined $hour and ($hour >= 12 and $hour <= 15)
!ll&&!rl&&r
000
$hour >= 12 and $hour <= 15
!ll&&!rl&&r
000
MC/DC0%0/3
defined $hour and ($hour >= 12 and $hour <= 15)
defined $hour $hour >= 12 $hour <= 15
Truth table0%0/4
A and B and C
A= defined $hourB= $hour >= 12C= $hour <= 15
ABCresult
0XX0
10X0
1100
1111
66 0 return 1;
67 }
68 else {
69 0 return 0;
70 }
71 }
72  
73 =head2 temperatures
74  
75 Returns an array reference of all the L<Weather::YR::Model::Temperature>
76 data points for this day.
77  
78 =cut
79  
80 sub _build_temperatures {
81 0 ▶ my $self = shift;
Subroutine _build_temperatures: not called CC=1 SCAR=6.9
82  
83 0 return [ map { $_->temperature } @{$self->datapoints} ];
84 }
85  
86 =head2 temperature
87  
88 Returns the "most logical" L<Weather::YR::Model::Temperature> data point for
89 this day.
90  
91 This works so that if you are working with "now", it will pick the data point
92 closest to the current time. If you are working with any other days, including
93 "today", it will return the data noon point, or the closest one after noon if
94 there isn't one for noon.
95  
96 =cut
97  
98 sub _build_temperature {
99 0 ▶ my $self = shift;
Subroutine _build_temperature: not called CC=3 SCAR=24.8
100  
101 0 foreach ( @{$self->temperatures} ) {
102 0 ▶ if ( $self->_ok_hour($_->from->hour) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_ok_hour($_->from->hour)) 0 0 0
103 0 return $_;
104 }
105 }
106  
107 0 return $self->temperatures->[0];
108 }
109  
110 =head2 precipitations
111  
112 Returns an array reference of all the L<Weather::YR::Model::Precipitation>
113 data points for this day.
114  
115 =cut
116  
117 sub _build_precipitations {
118 0 ▶ my $self = shift;
Subroutine _build_precipitations: not called CC=4 SCAR=30.0
119  
120 0 my @precips = ();
121  
122 0 foreach ( @{$self->datapoints} ) {
123 0 foreach ( @{$_->precipitations} ) {
124 0 ▶ if ( $_->from->ymd eq $self->date->ymd ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->from->ymd eq $self->date->ymd) 0 0 0
125 0 push( @precips, $_ );
126 }
127 }
128 }
129  
130 0 return \@precips;
131 }
132  
133 =head2 precipitation
134  
135 Returns "the most logical" L<Weather::YR::Model::Precipitation> data point
136 for this day.
137  
138 This works so that if you are working with "now", it will pick the data point
139 closest to the current time. If you are working with any other days, including
140 "today", it will return the data noon point, or the closest one after noon if
141 there isn't one for noon.
142  
143 =cut
144  
145 sub _build_precipitation {
146 0 ▶ my $self = shift;
Subroutine _build_precipitation: not called CC=3 SCAR=24.8
147  
148 0 foreach ( @{$self->precipitations} ) {
149 0 ▶ if ( $self->_ok_hour($_->from->hour) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_ok_hour($_->from->hour)) 0 0 0
150 0 return $_;
151 }
152 }
153  
154 0 return $self->precipitations->[0];
155 }
156  
157 =head2 wind_directions
158  
159 Returns an array reference of L<Weather::YR::Model::WindDirection> data points
160 for this day.
161  
162 =cut
163  
164 sub _build_wind_directions {
165 0 ▶ my $self = shift;
Subroutine _build_wind_directions: not called CC=1 SCAR=6.9
166  
167 0 return [ map { $_->wind_direction } @{$self->datapoints} ];
168 }
169  
170 =head2 wind_direction
171  
172 Returns "the most logical" L<Weather::YR::Model::WindDirection> data point
173 for this day.
174  
175 This works so that if you are working with "now", it will pick the data point
176 closest to the current time. If you are working with any other days, including
177 "today", it will return the data noon point, or the closest one after noon if
178 there isn't one for noon.
179  
180 =cut
181  
182 sub _build_wind_direction {
183 0 ▶ my $self = shift;
Subroutine _build_wind_direction: not called CC=3 SCAR=24.8
184  
185 0 foreach ( @{$self->wind_directions} ) {
186 0 ▶ if ( $self->_ok_hour($_->from->hour) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_ok_hour($_->from->hour)) 0 0 0
187 0 return $_;
188 }
189 }
190  
191 0 return $self->wind_directions->[0];
192 }
193  
194 =head2 wind_speeds
195  
196 Returns an array reference of L<Weather::YR::Model::WindSpeed> data points
197 for this day.
198  
199 =cut
200  
201 sub _build_wind_speeds {
202 0 ▶ my $self = shift;
Subroutine _build_wind_speeds: not called CC=1 SCAR=6.9
203  
204 0 return [ map { $_->wind_speed } @{$self->datapoints} ];
205 }
206  
207 =head2 wind_speed
208  
209 Returns "the most logical" L<Weather::YR::Model::WindSpeed> data point
210 for this day.
211  
212 This works so that if you are working with "now", it will pick the data point
213 closest to the current time. If you are working with any other days, including
214 "today", it will return the data noon point, or the closest one after noon if
215 there isn't one for noon.
216  
217 =cut
218  
219 sub _build_wind_speed {
220 0 ▶ my $self = shift;
Subroutine _build_wind_speed: not called CC=3 SCAR=24.8
221  
222 0 foreach ( @{$self->wind_speeds} ) {
223 0 ▶ if ( $self->_ok_hour($_->from->hour) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_ok_hour($_->from->hour)) 0 0 0
224 0 return $_;
225 }
226 }
227  
228 0 return $self->wind_speed->[0];
229 }
230  
231 =head2 humidities
232  
233 Returns an array reference of L<Weather::YR::Model::WindSpeed> data points
234 for this day.
235  
236 =cut
237  
238 sub _build_humidities {
239 0 ▶ my $self = shift;
Subroutine _build_humidities: not called CC=1 SCAR=6.9
240  
241 0 return [ map { $_->humidity } @{$self->datapoints} ];
242 }
243  
244 =head2 humidity
245  
246 Returns "the most logical" L<Weather::YR::Model::Humidity> data point
247 for this day.
248  
249 This works so that if you are working with "now", it will pick the data point
250 closest to the current time. If you are working with any other days, including
251 "today", it will return the data noon point, or the closest one after noon if
252 there isn't one for noon.
253  
254 =cut
255  
256 sub _build_humidity {
257 0 ▶ my $self = shift;
Subroutine _build_humidity: not called CC=3 SCAR=24.8
258  
259 0 foreach ( @{$self->humidities} ) {
260 0 ▶ if ( $self->_ok_hour($_->from->hour) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_ok_hour($_->from->hour)) 0 0 0
261 0 return $_;
262 }
263 }
264  
265 0 return $self->humidities->[0];
266 }
267  
268 =head2 pressures
269  
270 Returns an array reference of L<Weather::YR::Model::Pressure> data points
271 for this day.
272  
273 =cut
274  
275 sub _build_pressures {
276 0 ▶ my $self = shift;
Subroutine _build_pressures: not called CC=1 SCAR=6.9
277  
278 0 return [ map { $_->pressure } @{$self->datapoints} ];
279 }
280  
281 =head2 pressure
282  
283 Returns "the most logical" L<Weather::YR::Model::Humidity> data point
284 for this day.
285  
286 This works so that if you are working with "now", it will pick the data point
287 closest to the current time. If you are working with any other days, including
288 "today", it will return the data noon point, or the closest one after noon if
289 there isn't one for noon.
290  
291 =cut
292  
293 sub _build_pressure {
294 0 ▶ my $self = shift;
Subroutine _build_pressure: not called CC=3 SCAR=24.8
295  
296 0 foreach ( @{$self->pressures} ) {
297 0 ▶ if ( $self->_ok_hour($_->from->hour) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_ok_hour($_->from->hour)) 0 0 0
298 0 return $_;
299 }
300 }
301  
302 0 return $self->pressures->[0];
303 }
304  
305 =head2 cloudinesses
306  
307 Returns an array reference of L<Weather::YR::Model::Cloudiness> data points
308 for this day.
309  
310 =cut
311  
312 sub _build_cloudinesses {
313 0 ▶ my $self = shift;
Subroutine _build_cloudinesses: not called CC=1 SCAR=6.9
314  
315 0 return [ map { $_->cloudiness } @{$self->datapoints} ];
316 }
317  
318 =head2 cloudiness
319  
320 Returns "the most logical" L<Weather::YR::Model::Cloudiness> data point
321 for this day.
322  
323 This works so that if you are working with "now", it will pick the data point
324 closest to the current time. If you are working with any other days, including
325 "today", it will return the data noon point, or the closest one after noon if
326 there isn't one for noon.
327  
328 =cut
329  
330 sub _build_cloudiness {
331 0 ▶ my $self = shift;
Subroutine _build_cloudiness: not called CC=3 SCAR=24.8
332  
333 0 foreach ( @{$self->cloudinesses} ) {
334 0 ▶ if ( $self->_ok_hour($_->from->hour) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_ok_hour($_->from->hour)) 0 0 0
335 0 return $_;
336 }
337 }
338  
339 0 return $self->cloudinesses->[0];
340 }
341  
342 =head2 fogs
343  
344 Returns an array reference of L<Weather::YR::Model::Fog> data points
345 for this day.
346  
347 =cut
348  
349 sub _build_fogs {
350 0 ▶ my $self = shift;
Subroutine _build_fogs: not called CC=1 SCAR=6.9
351  
352 0 return [ map { $_->fog } @{$self->datapoints} ];
353 }
354  
355 =head2 fog
356  
357 Returns "the most logical" L<Weather::YR::Model::Fog> data point
358 for this day.
359  
360 This works so that if you are working with "now", it will pick the data point
361 closest to the current time. If you are working with any other days, including
362 "today", it will return the data noon point, or the closest one after noon if
363 there isn't one for noon.
364  
365 =cut
366  
367 sub _build_fog {
368 0 ▶ my $self = shift;
Subroutine _build_fog: not called CC=3 SCAR=24.8
369  
370 0 foreach ( @{$self->fogs} ) {
371 0 ▶ if ( $self->_ok_hour($_->from->hour) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_ok_hour($_->from->hour)) 0 0 0
372 0 return $_;
373 }
374 }
375  
376 0 return $self->fogs->[0];
377 }
378  
379 =head2 dew_point_temperatures
380  
381 Returns an array reference of L<Weather::YR::Model::DewPointTemperature> data points
382 for this day.
383  
384 =cut
385  
386 sub _build_dew_point_temperatures {
387 0 ▶ my $self = shift;
Subroutine _build_dew_point_temperatures: not called CC=1 SCAR=6.9
388  
389 0 return [ map { $_->dew_point_temperature } @{$self->datapoints} ];
390 }
391  
392 =head2 dew_point_temperature
393  
394 Returns "the most logical" L<Weather::YR::Model::DewPointTemperature> data point
395 for this day.
396  
397 This works so that if you are working with "now", it will pick the data point
398 closest to the current time. If you are working with any other days, including
399 "today", it will return the data noon point, or the closest one after noon if
400 there isn't one for noon.
401  
402 =cut
403  
404 sub _build_dew_point_temperature {
405 0 ▶ my $self = shift;
Subroutine _build_dew_point_temperature: not called CC=3 SCAR=24.8
406  
407 0 foreach ( @{$self->dew_point_temperatures} ) {
408 0 ▶ if ( $self->_ok_hour($_->from->hour) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_ok_hour($_->from->hour)) 0 0 0
409 0 return $_;
410 }
411 }
412  
413 0 return $self->dew_point_temperatures->[0];
414 }
415  
416 #
417 # The End
418 #
419 3 __PACKAGE__->meta->make_immutable;
420  
421 3 1;
↑ Summary YR/Base.pm »