NAME
Weather::NHC::TropicalCyclone - Provides a convenient interface to NHC's Tropical Cyclone JSON format.
SYNOPSIS
use strict;
use warnings;
use Weather::NHC::TropicalCyclone ();
my $nhc = Weather::NHC::TropicalCyclone->new;
$nhc->fetch;
my $storms_ref = $nhc->active_storms;
foreach my $storm (@$storms_ref) {
print $storm->name . qq{\n};
my ($text, $advNum, $local_file) = $storm->fetch_publicAdvisory($storm->id.q{.fst});
print qq{$local_file saved for Advisory $advNum\n};
print $text;
}
METHODS
new
-
Constructor - doesn't do much, but provide a convenient instance for the other provided methods described below.
fetch
-
Makes an HTTP request to $Weather::NHC::TropicalCyclone::DEFAULT_URL to get the JSON provided by the NHC describing the current set of active storms.
If the JSON is malformed or otherwise can't be parsed,
fetch
will throw an exception.Fetch will time out after
$Weather::NHC::TropicalCyclone::DEFAULT_TIMEOUT
by throwing an exception. In order to disable the alarm, callfetch
with a parameter of 0:$nhc->fetch(0);
active_storms
-
Provides an array reference of
Weather::NHC::TropicalCyclone::Storm
instances, one for each active storm. If there are no storms, the array reference returned is empty (not undef).Most of the useful functionality related to this JSON data is available through the methods provided by the
Weather::NHC::TropicalCyclone::Storm
instances returned by this method.
Auxillary RSS Fetch Methods
The following methods are provided to fetch the raw text of some of the RSS feeds available at https://www.nhc.noaa.gov/aboutrss.shtml.
my $nhc = Weather::NHC::TropicalStorm->new;
my $at_rss_text = $nhc->fetch_rss_atlantic;
my $ep_rss_text = $nhc->fetch_rss_east_pacific;
my $cp_rss_text = $nhc->fetch_rss_central_pacific;
Note: This module doesn't provide facilities for converting this RSS into a Perl data structure. For this, use a module like XML::RSS.
All methods provide return the text of the RSS. If an optional parameter is passed to the call that specifies a local file, the contents retrieved is saved to this file.
fetch_rss_atlantic_basin
-
Fetches RSS available at https://www.nhc.noaa.gov/index-at.xml. Internally, this URL is defined with the package variable,
$DEFAULT_RSS_ATLANTIC
. fetch_rss_east_pacific_basin
-
Fetches RSS available at https://www.nhc.noaa.gov/index-ep.xml. Internally, this URL is defined with the package variable,
$DEFAULT_RSS_EAST_PACIFIC
. fetch_rss_central_pacific_basin
-
Fetches RSS available at https://www.nhc.noaa.gov/index-cp.xml. Internally, this URL is defined with the package variable,
$DEFAULT_RSS_CENTRAL_PACIFIC
.
COPYRIGHT and LICENSE
This module is distributed under the same terms as Perl itself.