Class representing one location and its weather
#!/usr/bin/perl -w use Weather::Com::Finder;
# you have to fill in your ids from weather.com here my $PartnerId = 'somepartnerid'; my $LicenseKey = 'mylicense';
my %weatherargs = ( 'partner_id' => $PartnerId, 'license' => $LicenseKey, );
my $finder = Weather::Com::Finder->new(%weatherargs);
# if you want an array of locations: my @locations = $finder->find('Heidelberg');
# or if you prefer an arrayref: my $locations = $finder->find('Heidelberg');
foreach my $location (@locations) { print "Found weather for city: ", $location->name(), "\n"; print "The city is located at: ", $location->latitude(), "deg N, ", $location->longitude(), "deg E\n"; print "Local time is ", $location->localtime()->time(), "\n"; print "Sunrise will be/has been at ", $location->sunrise()->time(), "\n";
}
Using Weather::Com::Location objects is the way to access weather (and some location) information for one specific location (city).
You get Weather::Com::Location objects by using a finder object (see Weather::Com::Finder).
Weather::Com::Location is a subclass of Weather::Com::Cached. An instance of this class will update itself corresponding to the caching rules any time one of its methods is called.
\$1
The constructor will usually not be used directly because you get ready to use location objects by using a finder.
If you ever want to instantiate location objects on your own, you have to provide the same configuration hash or hashref to the constructor you usually would provide to the \*(C`new()\*(C' method of Weather::Com::Finder. In addition it is necessary to add a hash element \*(C`location_id\*(C' to this config hash. The \*(C`location_id\*(C' has to be a valid weather.com location id.
Returns the location id used to instantiate this location. Returns the name of the location as provided by weather.com. Returns a Weather::Com::CurrentConditions object containing the current conditions of the location.
The Weather::Com::CurrentConditions object is instantiated with the first call of the \*(C`current_conditions()\*(C' method.
Please refer to Weather::Com::CurrentConditions for further details. Returns a Weather::Com::Forecast object.
Please refer to Weather::Com::Forecast for further details. Returns the latitude of the location. Returns the longitude of the location. Returns a Weather::Com::DateTime object containing the local time of the location.
This value is evaluated each time you call this method. We do not use the value returned from weather.com here because it does not make any sence to use a cached value to show the current time. This method is deprecated and will be removed with the next release!
Returns the local time of the location.
The time is returned in the format \*(C`hh:mm [AM|PM]\*(C'. To get a 24 hour format use \*(C`localtime\*(C' instead.
Sample: 10:30 PM Returns a Weather::Com::DateTime object containing the time of sunrise. This method is deprecated and will be removed with the next release!
Returns the time of sunrise in 12 hour format (see \*(C`localtime_ampm()\*(C' for details). Returns a Weather::Com::DateTime object containing the time of sunset. This method is deprecated and will be removed with the next release!
Returns the time of sunset in 12 hour format (see \*(C`localtime_ampm()\*(C' for details). Returns the timezone offset to \s-1GMT\s0 (without respecting daylight savings time). Returns a Weather::Com::Units object.
Please refer to Weather::Com::Units for further details.
See also documentation of Weather::Com, Weather::Com::CurrentConditions, Weather::Com::Units.
Thomas Schnuecker, <[email protected]>
Copyright (C) 2004-2007 by Thomas Schnuecker
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The data provided by weather.com and made accessible by this \s-1OO\s0 interface can be used for free under special terms. Please have a look at the application programming guide of weather.com (http://www.weather.com/services/xmloap.html)