package Weather::Bug::Forecast; use warnings; use strict; use Moose; use XML::LibXML; use Weather::Bug::Temperature; our $VERSION = '0.20'; has 'title' => ( is => 'ro', isa => 'Str', init_arg => '-title' ); has 'short_title' => ( is => 'ro', isa => 'Str', init_arg => '-short' ); has 'imageurl' => ( is => 'ro', isa => 'Str', init_arg => '-image' ); has 'description' => ( is => 'ro', isa => 'Str', init_arg => '-desc' ); has 'prediction' => ( is => 'ro', isa => 'Str', init_arg => '-pred' ); has 'high' => ( is => 'ro', isa => 'Weather::Bug::Temperature', init_arg => '-high' ); has 'low' => ( is => 'ro', isa => 'Weather::Bug::Temperature', init_arg => '-low' ); sub from_xml { my $class = shift; my $node = shift; my ($hi) = $node->findnodes( 'aws:high' ); my ($lo) = $node->findnodes( 'aws:low' ); die "No 'aws:high' node found.\n" unless defined $hi; die "No 'aws:low' node found.\n" unless defined $lo; return Weather::Bug::Forecast->new( -title => $node->findvalue( 'aws:title' ), -short => $node->findvalue( 'aws:short-title' ), -image => $node->findvalue( 'aws:image' ), -desc => $node->findvalue( 'aws:description' ), -pred => $node->findvalue( 'aws:prediction' ), -high => Weather::Bug::Temperature->from_xml( $hi ), -low => Weather::Bug::Temperature->from_xml( $lo ), ); } 1; # Magic true value required at end of module __END__ =head1 NAME Weather::Bug::Forecast - Simple class interface to a single forecast from the WeatherBug API. =head1 VERSION This document describes Weather::Bug::Forecast version 0.20 =head1 SYNOPSIS use Weather::Bug; my $wbug = Weather::Bug->new( 'YOURAPIKEYHERE' ); my $fc = $wbug->get_forecast( 77096 ); printf( "Forecast for \%s, \%s at \%s, on \%s\n", $fc->location()->city(), $fc->location()->state(), $fc->date()->hms(), $fc->date->ymd() ); foreach my $f ($fc->forecasts()) { my $hi = $f->high(); my $lo = $f->low(); print $f->title(), ":\n", ($hi->is_null() ? "" : "\tHigh: $hi\n"), ($lo->is_null() ? "" : "\tLow: $lo\n"), $f->prediction(), "\n"; } =head1 DESCRIPTION This object encapsulates a single Forecast from the 7-day forecast response from the WeatherBug API. A FullForecast object contains a list of Forecast objects, each of which describes one forecast. =head1 INTERFACE =head2 Accessor Methods The methods providing access to the location's fields are: =over 4 =item title String explaining the time period of the forecast. =item short_title A short version of the prediction containing just the most important information. =item imageurl URL of an image characterizing the forecast. =item description Effectively the same information as the I