| 1 | package Weather::OpenWeatherMap; | ||||||||||||||||||||||||||||
| 2 | 1 | $Weather::OpenWeatherMap::VERSION = '0.003001'; | |||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strictures 2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Types::Standard -all; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Weather::OpenWeatherMap::Cache; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Weather::OpenWeatherMap::Error; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # Full require list to make Storable retrievals comfortable: | ||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Weather::OpenWeatherMap::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | require Weather::OpenWeatherMap::Request::Current; | |||||||||||||||||||||||||||
| 18 | 1 | require Weather::OpenWeatherMap::Request::Forecast; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Weather::OpenWeatherMap::Result; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | require Weather::OpenWeatherMap::Result::Current; | |||||||||||||||||||||||||||
| 22 | 1 | require Weather::OpenWeatherMap::Result::Forecast; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =pod | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =for Pod::Coverage has_api_key | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | has api_key => ( | ||||||||||||||||||||||||||||
| 33 | lazy => 1, | ||||||||||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||||||||||
| 35 | isa => Str, | ||||||||||||||||||||||||||||
| 36 | predicate => 1, | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | builder => sub { '' }, | ||||||||||||||||||||||||||
|
Subroutine
_build_api_key: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 38 | 1 | ); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | has cache => ( | ||||||||||||||||||||||||||||
| 41 | lazy => 1, | ||||||||||||||||||||||||||||
| 42 | is => 'ro', | ||||||||||||||||||||||||||||
| 43 | isa => Bool, | ||||||||||||||||||||||||||||
| 44 | 1 | ▶ | builder => sub { 0 }, | ||||||||||||||||||||||||||
|
Subroutine
_build_cache: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 1 | ); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | has cache_dir => ( | ||||||||||||||||||||||||||||
| 48 | lazy => 1, | ||||||||||||||||||||||||||||
| 49 | is => 'ro', | ||||||||||||||||||||||||||||
| 50 | isa => Maybe[Str], | ||||||||||||||||||||||||||||
| 51 | 1 | ▶ | builder => sub { undef }, | ||||||||||||||||||||||||||
|
Subroutine
_build_cache_dir: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | 1 | ); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | has cache_expiry => ( | ||||||||||||||||||||||||||||
| 55 | lazy => 1, | ||||||||||||||||||||||||||||
| 56 | is => 'ro', | ||||||||||||||||||||||||||||
| 57 | isa => Maybe[StrictNum], | ||||||||||||||||||||||||||||
| 58 | 1 | ▶ | builder => sub { undef }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | 1 | ); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | has _cache => ( | ||||||||||||||||||||||||||||
| 62 | lazy => 1, | ||||||||||||||||||||||||||||
| 63 | is => 'ro', | ||||||||||||||||||||||||||||
| 64 | isa => InstanceOf['Weather::OpenWeatherMap::Cache'], | ||||||||||||||||||||||||||||
| 65 | builder => sub { | ||||||||||||||||||||||||||||
| 66 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_build__cache: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 67 | 1 | ▶ | Weather::OpenWeatherMap::Cache->new( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 68 | ( $self->cache_dir ? (dir => $self->cache_dir) : () ), | ||||||||||||||||||||||||||||
| 69 | ( $self->cache_expiry ? (expiry => $self->cache_expiry) : () ), | ||||||||||||||||||||||||||||
| 70 | ) | ||||||||||||||||||||||||||||
| 71 | }, | ||||||||||||||||||||||||||||
| 72 | 1 | ); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | has ua => ( | ||||||||||||||||||||||||||||
| 76 | is => 'ro', | ||||||||||||||||||||||||||||
| 77 | isa => InstanceOf['LWP::UserAgent'], | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | builder => sub { LWP::UserAgent->new(timeout => 60) }, | ||||||||||||||||||||||||||
|
Subroutine
_build_ua: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 79 | 1 | ); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | sub get_weather { | ||||||||||||||||||||||||||||
| 83 | 5 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_weather: called CC=13 SCAR=26.9
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 5 | ▶ | croak "Missing 'location =>' in query" unless $args{location}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | my $type = | ||||||||||||||||||||||||||||
| 88 | delete $args{forecast} ? 'Forecast' | ||||||||||||||||||||||||||||
| 89 | 5 | ▶ | : delete $args{find} ? 'Find' | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 90 | : 'Current'; | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 5 | ▶ | my $my_request = Weather::OpenWeatherMap::Request->new_for( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->has_api_key and length $self->api_key
MC/DC0%0/2
$self->has_api_key and length $self->api_key
$self->has_api_key
length $self->api_key
Truth table33%1/3
A and B
A= $self->has_api_keyB= length $self->api_key
| |||||||||||||||||||||||||||||
| 93 | $type => | ||||||||||||||||||||||||||||
| 94 | ( | ||||||||||||||||||||||||||||
| 95 | $self->has_api_key && length $self->api_key ? | ||||||||||||||||||||||||||||
| 96 | ( api_key => $self->api_key ) : () | ||||||||||||||||||||||||||||
| 97 | ), | ||||||||||||||||||||||||||||
| 98 | %args | ||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 5 | my $result; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 5 | ▶ | if ( $self->cache && (my $cached = $self->_cache->retrieve($my_request)) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->cache and my $cached = $self->_cache->retrieve($my_request)
MC/DC100%2/2
$self->cache and my $cached = $self->_cache->retrieve($my_request)
$self->cache
my $cached = $self->_cache->retrieve($my_request)
Truth table100%3/3
A and B
A= $self->cacheB= my $cached = $self->_cache->retrieve($my_request)
| |||||||||||||||||||||||||||||
| 104 | 1 | $result = $cached->object | |||||||||||||||||||||||||||
| 105 | } else { | ||||||||||||||||||||||||||||
| 106 | 4 | my $http_response = $self->ua->request( $my_request->http_request ); | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 4 | ▶ | unless ($http_response->is_success) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | die Weather::OpenWeatherMap::Error->new( | |||||||||||||||||||||||||||
| 110 | request => $my_request, | ||||||||||||||||||||||||||||
| 111 | source => 'http', | ||||||||||||||||||||||||||||
| 112 | status => $http_response->status_line, | ||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 4 | ▶ | $result = Weather::OpenWeatherMap::Result->new_for( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$my_request->can("hourly") and $my_request->hourly
MC/DC100%2/2
$my_request->can("hourly") and $my_request->hourly
$my_request->can("hourly")
$my_request->hourly
Truth table100%3/3
A and B
A= $my_request->can("hourly")B= $my_request->hourly
| |||||||||||||||||||||||||||||
| 117 | $type => | ||||||||||||||||||||||||||||
| 118 | request => $my_request, | ||||||||||||||||||||||||||||
| 119 | json => $http_response->content, | ||||||||||||||||||||||||||||
| 120 | ( | ||||||||||||||||||||||||||||
| 121 | $my_request->can('hourly') && $my_request->hourly ? | ||||||||||||||||||||||||||||
| 122 | (hourly => 1) : () | ||||||||||||||||||||||||||||
| 123 | ), | ||||||||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 5 | ▶ | unless ($result->is_success) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | die Weather::OpenWeatherMap::Error->new( | |||||||||||||||||||||||||||
| 129 | request => $my_request, | ||||||||||||||||||||||||||||
| 130 | source => 'api', | ||||||||||||||||||||||||||||
| 131 | status => $result->error, | ||||||||||||||||||||||||||||
| 132 | ) | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 5 | ▶ | $self->_cache->cache($result) if $self->cache; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 5 | $result | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 1 | 1; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =pod | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =head1 NAME | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | Weather::OpenWeatherMap - Interface to the OpenWeatherMap API | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | use Weather::OpenWeatherMap; | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | my $api_key = 'foo'; | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | my $wx = Weather::OpenWeatherMap->new( | ||||||||||||||||||||||||||||
| 156 | api_key => $api_key, | ||||||||||||||||||||||||||||
| 157 | ); | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | # Current conditions: | ||||||||||||||||||||||||||||
| 160 | # (see Weather::OpenWeatherMap::Result::Current) | ||||||||||||||||||||||||||||
| 161 | my $current = $wx->get_weather( | ||||||||||||||||||||||||||||
| 162 | location => 'Manchester, NH', | ||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||
| 164 | my $tempf = $current->temp_f; | ||||||||||||||||||||||||||||
| 165 | my $wind = $current->wind_speed_mph; | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | # Daily forecast conditions: | ||||||||||||||||||||||||||||
| 168 | # (see Weather::OpenWeatherMap::Result::Forecast) | ||||||||||||||||||||||||||||
| 169 | my $forecast = $wx->get_weather( | ||||||||||||||||||||||||||||
| 170 | location => 'Manchester, NH', | ||||||||||||||||||||||||||||
| 171 | forecast => 1, | ||||||||||||||||||||||||||||
| 172 | days => 3, | ||||||||||||||||||||||||||||
| 173 | ); | ||||||||||||||||||||||||||||
| 174 | for my $day ($forecast->list) { | ||||||||||||||||||||||||||||
| 175 | my $date = $day->dt->mdy; | ||||||||||||||||||||||||||||
| 176 | my $temp_lo = $day->temp_min_f, | ||||||||||||||||||||||||||||
| 177 | my $temp_hi = $day->temp_max_f, | ||||||||||||||||||||||||||||
| 178 | # (see Weather::OpenWeatherMap::Result::Forecast::Day) | ||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | # Hourly (3-hr blocks) forecast conditions: | ||||||||||||||||||||||||||||
| 182 | my $forecast = $wx->get_weather( | ||||||||||||||||||||||||||||
| 183 | location => 'Manchester, NH', | ||||||||||||||||||||||||||||
| 184 | forecast => 1, | ||||||||||||||||||||||||||||
| 185 | hourly => 1, | ||||||||||||||||||||||||||||
| 186 | days => 3, | ||||||||||||||||||||||||||||
| 187 | ); | ||||||||||||||||||||||||||||
| 188 | for my $block ($forecast->list) { | ||||||||||||||||||||||||||||
| 189 | my $time = $block->dt_txt; | ||||||||||||||||||||||||||||
| 190 | my $temp = $block->temp; | ||||||||||||||||||||||||||||
| 191 | # (see Weather::OpenWeatherMap::Result::Forecast::Hour) | ||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | # Find a city: | ||||||||||||||||||||||||||||
| 195 | # (see Weather::OpenWeatherMap::Result::Find) | ||||||||||||||||||||||||||||
| 196 | my $search = $wx->get_weather( | ||||||||||||||||||||||||||||
| 197 | location => 'Manchester', | ||||||||||||||||||||||||||||
| 198 | find => 1, | ||||||||||||||||||||||||||||
| 199 | max => 5, | ||||||||||||||||||||||||||||
| 200 | ); | ||||||||||||||||||||||||||||
| 201 | for my $place ($search->list) { | ||||||||||||||||||||||||||||
| 202 | my $region = $place->country; | ||||||||||||||||||||||||||||
| 203 | # ... | ||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | An object-oriented interface to retrieving weather conditions & forecasts from | ||||||||||||||||||||||||||||
| 209 | B<OpenWeatherMap> (L<http://www.openweathermap.org/>) for a given city, | ||||||||||||||||||||||||||||
| 210 | latitude/longitude, or OpenWeatherMap city code. | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | This module provides a simple blocking (L<LWP::UserAgent>) interface to | ||||||||||||||||||||||||||||
| 213 | weather retrieval; if you have an event loop handy, the included | ||||||||||||||||||||||||||||
| 214 | L<Weather::OpenWeatherMap::Request> & L<Weather::OpenWeatherMap::Result> | ||||||||||||||||||||||||||||
| 215 | classes can be used to create appropriate L<HTTP::Request> instances and parse | ||||||||||||||||||||||||||||
| 216 | responses from non-blocking HTTP clients. | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | See L<POEx::Weather::OpenWeatherMap> for a non-blocking implementation using | ||||||||||||||||||||||||||||
| 219 | the L<POE> ecosystem. | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | =head2 ATTRIBUTES | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | =head3 api_key | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | Your L<OpenWeatherMap|http://www.openweathermap.org/> API key. | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | (See L<http://www.openweathermap.org/api> to register for free.) | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | =head3 cache | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | A boolean value indicating whether successful results should be cached to | ||||||||||||||||||||||||||||
| 232 | disk via L<Weather::OpenWeatherMap::Cache>. | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | Defaults to false. This may change in a future release. | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | =head3 cache_dir | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | The directory in which cache files are saved. The default may be fine; see | ||||||||||||||||||||||||||||
| 239 | L<Weather::OpenWeatherMap::Cache>. | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | =head3 cache_expiry | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | The duration (in seconds) for which cache files are considered valid; see | ||||||||||||||||||||||||||||
| 244 | L<Weather::OpenWeatherMap::Cache>. | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | =head3 ua | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | The L<LWP::UserAgent> instance used to issue HTTP requests; can be used to | ||||||||||||||||||||||||||||
| 249 | control LWP options: | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | my $wx = Weather::OpenWeatherMap->new( | ||||||||||||||||||||||||||||
| 252 | api_key => $my_api_key, | ||||||||||||||||||||||||||||
| 253 | ua => LWP::UserAgent->new(%lwp_opts), | ||||||||||||||||||||||||||||
| 254 | ); | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | =head2 METHODS | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | =head3 get_weather | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | $wx->get_weather( | ||||||||||||||||||||||||||||
| 261 | # 'location =>' is mandatory. | ||||||||||||||||||||||||||||
| 262 | # These are all valid location strings: | ||||||||||||||||||||||||||||
| 263 | # By name: | ||||||||||||||||||||||||||||
| 264 | # 'Manchester, NH' | ||||||||||||||||||||||||||||
| 265 | # 'London, UK' | ||||||||||||||||||||||||||||
| 266 | # By OpenWeatherMap city code: | ||||||||||||||||||||||||||||
| 267 | # 5089178 | ||||||||||||||||||||||||||||
| 268 | # By latitude/longitude: | ||||||||||||||||||||||||||||
| 269 | # 'lat 42, long -71' | ||||||||||||||||||||||||||||
| 270 | location => 'Manchester, NH', | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | # Set 'forecast => 1' to get the forecast, | ||||||||||||||||||||||||||||
| 273 | # omit or set to false for current weather: | ||||||||||||||||||||||||||||
| 274 | forecast => 1, | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | # If 'forecast' is true, you can ask for an hourly (rather than daily) | ||||||||||||||||||||||||||||
| 277 | # forecast report: | ||||||||||||||||||||||||||||
| 278 | hourly => 1, | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | # If 'forecast' is true, you can specify the number of days to fetch | ||||||||||||||||||||||||||||
| 281 | # (up to 16 for daily reports, 5 for hourly reports): | ||||||||||||||||||||||||||||
| 282 | days => 3, | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | # Optional tag for identifying the response to this request: | ||||||||||||||||||||||||||||
| 285 | tag => 'foo', | ||||||||||||||||||||||||||||
| 286 | ); | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | Request a weather report (in the form of a L<Weather::OpenWeatherMap::Result> | ||||||||||||||||||||||||||||
| 289 | object) for the given C<< location => >>. | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | The location can be a 'City, State' or 'City, Country' string, an | ||||||||||||||||||||||||||||
| 292 | L<OpenWeatherMap|http://www.openweathermap.org/> city code, or a 'lat X, long | ||||||||||||||||||||||||||||
| 293 | Y' string. | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | Requests the current weather by default (see | ||||||||||||||||||||||||||||
| 296 | L<Weather::OpenWeatherMap::Request::Current> and | ||||||||||||||||||||||||||||
| 297 | L<Weather::OpenWeatherMap::Result::Current>). | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | If passed C<< forecast => 1 >>, requests a weather forecast (see | ||||||||||||||||||||||||||||
| 300 | L<Weather::OpenWeatherMap::Request::Forecast> and | ||||||||||||||||||||||||||||
| 301 | L<Weather::OpenWeatherMap::Result::Forecast>), in which case C<< days => | ||||||||||||||||||||||||||||
| 302 | $count >> and/or C<< hourly => $bool >> can be specified. | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | If passed C<< find => 1 >>, requests search results for a given location name | ||||||||||||||||||||||||||||
| 305 | or latitude & longitude; see L<Weather::OpenWeatherMap::Request::Find> and | ||||||||||||||||||||||||||||
| 306 | L<Weather::OpenWeatherMap::Result::Find>. | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | Any extra arguments are passed to the constructor for the appropriate Request | ||||||||||||||||||||||||||||
| 309 | subclass; see L<Weather::OpenWeatherMap::Request>. | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | L<Weather::OpenWeatherMap::Result> | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | L<POEx::Weather::OpenWeatherMap> | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | Jon Portnoy <avenj@cobaltirc.org> | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | =cut | ||||||||||||||||||||||||||||