Weather::Bug::Location - Simple class interface to the location of a WeatherBug Station or observation.
This document describes Weather::Bug::Location version 0.25
use Weather::Bug; my $wbug = Weather::Bug->new( 'YOURAPIKEYHERE' ); my ($station) = $wbug->list_stations( 77096 ); my $l = $station->location(); printf( "%s, %s %s\n\t(%0.5f,%0.5f), (dist=%0.3f)\n", $l->city(), $l->state(), $l->zipcode(), $l->latitude(), $l->longitude(), $l->distance() );
Each type of response has its own concept of what Location information should look like. This class abstracts away the differences (as much as possible) providing a mostly common interface. Unfortunately, some of the responses provide more information than others, so it is not always possible to get all of the same information from each Location object.
The Location object should always provide three pieces of information: city, state, and zipcode. Depending on where it was obtained, it may also contain latitude and longitude of the site, distance from the center of the requested zip code, and/or a zone string representing a general location in the US.
Each field has its own accessor method. If the field is optional, it will also have a has_ method that tells whether or not the field is present.
The Location is basically a data object that only provides read access to its fields. The methods of this class can be separated into two groups, accessor methods and factory methods.
The methods providing access to the Location's fields are:
The Location's city as a string. Always available.
The Location's state as a string. Always available.
The Location's zip code as a string. Always available.
Boolean value telling whether or not latitude is available.
The Location's latitude as a float. Always available.
Boolean value telling whether or not longitude is available.
The Location's longitude as a float. Always available.
Boolean value telling whether or not distance is available.
The Location's distance from the center of the zip code as a float. Always available.
Boolean value telling whether or not zone is available.
A string telling the general region of the US that the Location describes.
Returns a true value if the supplied Location is equvalent.
$loc->is_equivalent( $other );
Equivalence, in this case, is defined as all of the required fields are the same. The optional fields are also tested in the case where both of the Location objects do have that field. So, if either Location is missing a field (say, distance) this field will not be compared.
Since the object is usually created from an XML repsonse, the class provides factory methods that take a portion of the XML and return a Location.
Construct a Location from the
aws:station node returned by the getStations API method. The only argument is the node to parse.
The created Location will have the following fields: city, state, zipcode, latitude, longitude, and distance (from the center of the zipcode supplied to getStations).
Returns a Location object on success.
Construct a Location object from the
aws:location node returned by the getFullForecast API method. The only argument is the node to parse.
The created Location will have the following fields: city, state, zipcode, and zone.
Returns a Location object on success.
Construct a Location object from a getLiveWeather request.
Returns a Location object on success or dies if the city and state cannot be parsed.
City/State not formatted as expected.
The Live Weather mixes the City and State together in one node value. This value was not formatted in a way that allowed the module to parse the result.
Weather::Bug requires no configuration files or environment variables.
No bugs have been reported.
Please report any bugs or feature requests to
firstname.lastname@example.org, or through the web interface at http://rt.cpan.org.
G. Wade Johnson
Copyright (c) 2008, G. Wade Johnson
<email@example.com>. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.