| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 1 |  |  | 1 |  | 57602 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 25 |  | 
| 2 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 52 |  | 
| 3 |  |  |  |  |  |  | package App::wu; | 
| 4 |  |  |  |  |  |  | $App::wu::VERSION = '0.06'; | 
| 5 | 1 |  |  | 1 |  | 430 | use WWW::Wunderground::API 0.06; | 
|  | 1 |  |  |  |  | 110273 |  | 
|  | 1 |  |  |  |  | 28 |  | 
| 6 | 1 |  |  | 1 |  | 388 | use Cache::FileCache; | 
|  | 1 |  |  |  |  | 30158 |  | 
|  | 1 |  |  |  |  | 44 |  | 
| 7 | 1 |  |  | 1 |  | 8 | use Carp; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 46 |  | 
| 8 | 1 |  |  | 1 |  | 5 | use Try::Tiny; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 329 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | #ABSTRACT: Terminal app that provides an hourly weather forecast using Weather Underground API | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | sub new | 
| 16 |  |  |  |  |  |  | { | 
| 17 | 1 | 50 |  | 1 | 0 | 82 | croak 'Incorrect number of args passed to constructor' unless @_ == 3; | 
| 18 | 1 |  |  |  |  | 3 | my ($class, $location, $api_key) = @_; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 1 |  |  |  |  | 10 | my $wu = new WWW::Wunderground::API( | 
| 21 |  |  |  |  |  |  | location => $location, | 
| 22 |  |  |  |  |  |  | api_key  => $api_key, | 
| 23 |  |  |  |  |  |  | auto_api => 1, | 
| 24 |  |  |  |  |  |  | cache    => Cache::FileCache->new({ | 
| 25 |  |  |  |  |  |  | namespace          => 'wundercache', | 
| 26 |  |  |  |  |  |  | default_expires_in => 2400 }), | 
| 27 |  |  |  |  |  |  | ); | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 1 |  |  |  |  | 2123 | return bless { wu => $wu }, $class; | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | sub print_hourly | 
| 33 |  |  |  |  |  |  | { | 
| 34 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 35 | 0 |  |  |  |  |  | my $wu = $self->{wu}; | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | try { | 
| 38 | 0 |  |  | 0 |  |  | my @hourly_results = @{ $wu->hourly }; | 
|  | 0 |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | # print header | 
| 41 | 0 |  |  |  |  |  | binmode STDOUT, ':utf8'; # for degrees symbol | 
| 42 | 0 |  |  |  |  |  | printf "%-10s%-4s%-4s%-8s%-20s\n", | 
| 43 |  |  |  |  |  |  | 'Time', | 
| 44 |  |  |  |  |  |  | "\x{2109}", | 
| 45 |  |  |  |  |  |  | "\x{2103}", | 
| 46 |  |  |  |  |  |  | 'Rain %', | 
| 47 |  |  |  |  |  |  | 'Conditions'; | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | # print hourly | 
| 50 | 0 |  |  |  |  |  | for (@hourly_results) | 
| 51 |  |  |  |  |  |  | { | 
| 52 |  |  |  |  |  |  | printf "%8s%4i%4i%8i  %-30s\n", | 
| 53 |  |  |  |  |  |  | $_->{FCTTIME}{civil}, | 
| 54 |  |  |  |  |  |  | $_->{temp}{english}, | 
| 55 |  |  |  |  |  |  | $_->{temp}{metric}, | 
| 56 |  |  |  |  |  |  | $_->{pop}, | 
| 57 | 0 |  |  |  |  |  | $_->{condition}; | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  | } catch | 
| 60 |  |  |  |  |  |  | {   # see if there is an error message to display | 
| 61 | 0 | 0 |  | 0 |  |  | if (exists $wu->{data}{hourly}{response}{error}{description}) | 
| 62 |  |  |  |  |  |  | { | 
| 63 | 0 |  |  |  |  |  | print "$wu->{data}{hourly}{response}{error}{description}\n"; | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  | else | 
| 66 |  |  |  |  |  |  | { | 
| 67 | 0 |  |  |  |  |  | print "Error connecting to Wunderground API (is your Internet connection active?)\n"; | 
| 68 |  |  |  |  |  |  | } | 
| 69 | 0 |  |  |  |  |  | }; | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | 1; | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | __END__ |