| 1 | package Weather::OpenWeatherMap::Result::Forecast; | ||||||||||||||||||||||||||||
| 2 | 2 | $Weather::OpenWeatherMap::Result::Forecast::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 Types::Standard -all; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use List::Objects::Types -all; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Weather::OpenWeatherMap::Result::Forecast::Day; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Weather::OpenWeatherMap::Result::Forecast::Hour; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =pod | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =for Pod::Coverage lazy_for | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub lazy_for { | ||||||||||||||||||||||||||||
| 19 | 16 | ▶ | my $type = shift; | ||||||||||||||||||||||||||
|
Subroutine
lazy_for: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | ( | ||||||||||||||||||||||||||||
| 21 | 16 | ▶ | lazy => 1, is => 'ro', isa => $type, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | ( $type->has_coercion ? (coerce => 1) : () ), | ||||||||||||||||||||||||||||
| 23 | @_ | ||||||||||||||||||||||||||||
| 24 | ) | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 2 | extends 'Weather::OpenWeatherMap::Result'; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | has hourly => ( lazy_for Bool, | ||||||||||||||||||||||||||||
| 31 | 4 | ▶ | builder => sub { shift->request->hourly ? 1 : 0 }, | ||||||||||||||||||||||||||
|
Subroutine
_build_hourly: called CC=2 SCAR=9.2
Subroutine
__ANON__: not called CC=2 SCAR=9.2
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 32 | 2 | ); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | has id => ( lazy_for Int, | ||||||||||||||||||||||||||||
| 35 | 4 | ▶ | builder => sub { shift->data->{city}->{id} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
_build_id: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 2 | ); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | has name => ( lazy_for Str, | ||||||||||||||||||||||||||||
| 39 | 4 | ▶ | builder => sub { shift->data->{city}->{name} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
_build_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 2 | ); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | has country => ( lazy_for Str, | ||||||||||||||||||||||||||||
| 43 | 4 | ▶ | builder => sub { shift->data->{city}->{country} }, | ||||||||||||||||||||||||||
|
Subroutine
_build_country: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 2 | ); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | has latitude => ( lazy_for StrictNum, | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | builder => sub { shift->data->{city}->{coord}->{lat} }, | ||||||||||||||||||||||||||
|
Subroutine
_build_latitude: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 48 | 2 | ); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | has longitude => ( lazy_for StrictNum, | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | builder => sub { shift->data->{city}->{coord}->{lon} }, | ||||||||||||||||||||||||||
|
Subroutine
_build_longitude: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 52 | 2 | ); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | has count => ( lazy_for Int, | ||||||||||||||||||||||||||||
| 55 | 5 | ▶ | builder => sub { shift->data->{cnt} // 0 }, | ||||||||||||||||||||||||||
|
Subroutine
_build_count: called CC=2 SCAR=7.6
Condition50%1/2
+(shift())->data->{"cnt"} // 0
MC/DC0%0/1
+(shift())->data->{"cnt"} // 0
+(shift())->data->{"cnt"}
Truth table50%1/2
A
A= +(shift())->data->{"cnt"}
| |||||||||||||||||||||||||||||
| 56 | 2 | ); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | has _forecast_list => ( lazy_for ArrayObj, | ||||||||||||||||||||||||||||
| 59 | builder => sub { | ||||||||||||||||||||||||||||
| 60 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=26.5
| |||||||||||||||||||||||||||||
| 61 | 5 | ▶ | my @list = @{ $self->data->{list} || [] }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 5 | ▶ | warn "No items in forecast list (name: @{[$self->name]})" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | unless @list; | ||||||||||||||||||||||||||||
| 64 | # FIXME test that bad items in @list warn and add nothing | ||||||||||||||||||||||||||||
| 65 | $self->request->hourly ? | ||||||||||||||||||||||||||||
| 66 | [ map {; | ||||||||||||||||||||||||||||
| 67 | 80 | ▶ | ref $_ eq 'HASH' ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
carp("Expected a HASH but got $_") and ()
MC/DC0%0/2
carp("Expected a HASH but got $_") and ()
carp("Expected a HASH but got $_")
()
Truth table0%0/3
A and B
A= carp("Expected a HASH but got $_")B= ()
| |||||||||||||||||||||||||||||
| 68 | Weather::OpenWeatherMap::Result::Forecast::Hour->new(%$_) | ||||||||||||||||||||||||||||
| 69 | : (carp "Expected a HASH but got $_" and ()) | ||||||||||||||||||||||||||||
| 70 | } @list ] | ||||||||||||||||||||||||||||
| 71 | 5 | ▶ | : [ map {; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 9 | ▶ | ref $_ eq 'HASH' ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
carp("expected a HASH but got $_") and ()
MC/DC0%0/2
carp("expected a HASH but got $_") and ()
carp("expected a HASH but got $_")
()
Truth table0%0/3
A and B
A= carp("expected a HASH but got $_")B= ()
| |||||||||||||||||||||||||||||
| 73 | Weather::OpenWeatherMap::Result::Forecast::Day->new(%$_) | ||||||||||||||||||||||||||||
| 74 | : (carp "expected a HASH but got $_" and ()) | ||||||||||||||||||||||||||||
| 75 | } @list ] | ||||||||||||||||||||||||||||
| 76 | }, | ||||||||||||||||||||||||||||
| 77 | 2 | ); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | sub as_array { | ||||||||||||||||||||||||||||
| 80 | 15 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
as_array: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | 15 | $self->_forecast_list->copy | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =for Pod::Coverage as_list | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 2 | ▶ | { no warnings 'once'; *as_list = *list } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 89 | sub list { | ||||||||||||||||||||||||||||
| 90 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 5 | $self->_forecast_list->all | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | sub iter { | ||||||||||||||||||||||||||||
| 95 | 5 | ▶ | my ($self, $count) = @_; | ||||||||||||||||||||||||||
|
Subroutine
iter: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 5 | ▶ | $self->_forecast_list->natatime($count || 1) | ||||||||||||||||||||||||||
|
Condition100%2/2
$count || 1
MC/DC100%1/1
$count || 1
$count
Truth table100%2/2
A
A= $count
| |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 2 | 1; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =pod | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head1 NAME | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | Weather::OpenWeatherMap::Result::Forecast - Weather forecast result | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | # Normally retrieved via Weather::OpenWeatherMap | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | This is a subclass of L<Weather::OpenWeatherMap::Result> containing the | ||||||||||||||||||||||||||||
| 115 | result of a completed L<Weather::OpenWeatherMap::Request::Forecast>. | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | These are normally emitted by a L<Weather::OpenWeatherMap> instance. | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =head2 ATTRIBUTES | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =head3 hourly | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | Boolean true if this is an hourly weather report. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =head3 count | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | The number of forecast days returned by the L<OpenWeatherMap | ||||||||||||||||||||||||||||
| 128 | API|http://www.openweathermap.org/api>. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | See L</list> and L</iter>. | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =head3 country | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | The country string. | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =head3 id | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | The L<OpenWeatherMap|http://www.openweathermap.org/> city code. | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =head3 latitude | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | The station's latitude. | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =head3 longitude | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | The station's longitude. | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =head3 name | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | The city name. | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =head2 METHODS | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =head3 as_array | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | The full forecast list, as a L<List::Objects::WithUtils::Array>. | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | See L</list>. | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =head3 list | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | The full forecast list; each item in the list is either a | ||||||||||||||||||||||||||||
| 163 | L<Weather::OpenWeatherMap::Result::Forecast::Day> (by default) or a | ||||||||||||||||||||||||||||
| 164 | L<Weather::OpenWeatherMap::Result::Forecast::Hour> (if L</hourly> is true) | ||||||||||||||||||||||||||||
| 165 | instance: | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | for my $day ($result->list) { | ||||||||||||||||||||||||||||
| 168 | my $date = $day->dt->mdy; | ||||||||||||||||||||||||||||
| 169 | my $cloudiness = $day->cloud_coverage; | ||||||||||||||||||||||||||||
| 170 | # ... | ||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | See the documentation for | ||||||||||||||||||||||||||||
| 174 | L<Weather::OpenWeatherMap::Result::Forecast::Day> & | ||||||||||||||||||||||||||||
| 175 | L<Weather::OpenWeatherMap::Result::Forecast::Hour>. | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | =head3 iter | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | Returns an iterator that, when called, returns the next | ||||||||||||||||||||||||||||
| 180 | L<Weather::OpenWeatherMap::Result::Forecast::Day> or | ||||||||||||||||||||||||||||
| 181 | L<Weather::OpenWeatherMap::Result::Forecast::Hour> instance (or undef when the | ||||||||||||||||||||||||||||
| 182 | list is empty): | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | my $iter = $result->iter; | ||||||||||||||||||||||||||||
| 185 | while (my $day = $iter->()) { | ||||||||||||||||||||||||||||
| 186 | my $wind = $day->wind_speed_mph; | ||||||||||||||||||||||||||||
| 187 | # ... | ||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | The number of items to return at a time can be provided (as of C<v0.4.x>): | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | my $iter = $result->iter(3); | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | See also: L</list> | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | L<Weather::OpenWeatherMap::Result> | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | L<Weather::OpenWeatherMap::Result::Forecast::Block> | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | L<Weather::OpenWeatherMap::Result::Forecast::Day> | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | L<Weather::OpenWeatherMap::Result::Forecast::Hour> | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | L<Weather::OpenWeatherMap::Result::Current> | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | Jon Portnoy <avenj@cobaltirc.org> | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | =cut | ||||||||||||||||||||||||||||