Weather::Com::Cached(3) Perl extension for getting weather information from weather.com

SYNOPSIS


use Data::Dumper;
use Weather::Com::Cached;

  # define parameters for weather search
  my %params = (
                'cache'      => '/tmp/weathercache',
                'current'    => 1,
                'forecast'   => 3,
                'links'      => 1,
                'units'      => 's',
                'proxy'      => 'http://proxy.sonstwo.de',
                'timeout'    => 250,
                'debug'      => 1,
                'partner_id' => 'somepartnerid',
                'license'    => '12345678',
  );

  # instantiate a new weather.com object
  my $cached_weather = Weather::Com::Cached->new(%params);

  # search for locations called 'Heidelberg'
  my $locations = $cached_weather->search('Heidelberg')
        or die "No location found!\n";

  # and then get the weather for each location found
  foreach (keys %{$locations}) {
        my $weather = $cached_weather->get_weather($_);
        print Dumper($weather);
  }

CHANGES

The location caching mechanism has been extended with version 0.4. Up to V0.4 searches were stored this way:

  $locations_cache = {
                'New York' => {
                         'USNY1000' => 'New York/La Guardia Arpt, NY',
                         'USNY0998' => 'New York/Central Park, NY',
                         'USNY0999' => 'New York/JFK Intl Arpt, NY',
                         'USNY0996' => 'New York, NY'
                },
  }

This has changed the way it does not only store a

  search_string => locations

hash. The cache now also stores a hash for each location name found:

  $locations_cache => {
        'new york' => {
                'USNY1000' => 'New York/La Guardia Arpt, NY',
                'USNY0998' => 'New York/Central Park, NY',
                'USNY0999' => 'New York/JFK Intl Arpt, NY',
                'USNY0996' => 'New York, NY'
        },
        'new york/central park, ny' => {
                'USNY0998' => 'New York/Central Park, NY'
        },
        'new york/la guardia arpt, ny' => {
                'USNY1000' => 'New York/La Guardia Arpt, NY'
        },
        'new york, ny' => {
                'USNY0996' => 'New York, NY'
        },
        'new york/jfk intl arpt, ny' => {
                'USNY0999' => 'New York/JFK Intl Arpt, NY'
        },
  }

The new mechanism has the following advantages:

1.
The new chaching mechanism is case insensitive
2.
This caching mechanism is a workaround one problem with weather.com's XOAP API.

Their server does not understand any search string with a '/' in it - no matter wether the '/' is URL encoded or not!

This way, if you have searched for New York once, you'll then also get a result for direct calls to New York/Jfk Intl Arpt, NY.

3.
The new mechanism also allows searches for slashed substrings. A search for York/Central will return the New York/Central Park, NY location and if you simply search York, you'll get anything containing York. No matter if it's in the cache or not.

Only if you specify exactly the name of a location in the cache, only this location is shown.