Weather::NHC::TropicalCyclone - Provides a convenient interface to NHC's Tropical Cyclone JSON format.
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; }
new
Constructor - doesn't do much, but provide a convenient instance for the other provided methods described below.
fetch(optional: timeout, optional: $file)
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
Fetch will time out after $Weather::NHC::TropicalCyclone::DEFAULT_TIMEOUT by throwing an exception. In order to disable the alarm, call fetch with a parameter of 0:
$Weather::NHC::TropicalCyclone::DEFAULT_TIMEOUT
$nhc->fetch(0);
There is a 2nd optional argument for specifying a file path which, if provided, will be used to save the contents of the fetched upstream file, CurrentStorms.json. However, for now a timeout has to be specified the first argument position. This will change in the future.
CurrentStorms.json
$nhc->fetch(120, q{/path/to/CurrentStorms.json});
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).
Weather::NHC::TropicalCyclone::Storm
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.
get_storm_ids
There are no parameters for this method.
Returns a list of storm ids (e.g., ep082019) that are listed in the storm cache.
get_storm_by_id
This methods requires a single parameter, and it should be of the form of a storm id, e.g., 'al202020', 'cp062006', etc. If the storm exists in the cache, it returns an instance of Weather::NHC::TropicalCyclone::Storm. If there is no matching storm id, then it returns undef.
Provides a constant time look up of storms stored in the internal storm cache that is updated whenever fetch is called.
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.
$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.
$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.
$DEFAULT_RSS_CENTRAL_PACIFIC
_update_storm_cache
This methods is used by fetch to update the internal cache when a new JSON file is processed. The internal cache facilitates constant time look up of storms using the get_storm_by_id. This internal cache is also the source of the storm ids returned by get_storm_ids.
This module is distributed under the same terms as Perl itself.
To install Weather::NHC::TropicalCyclone, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Weather::NHC::TropicalCyclone
CPAN shell
perl -MCPAN -e shell install Weather::NHC::TropicalCyclone
For more information on module installation, please visit the detailed CPAN module installation guide.