line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Weather::Airport; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
33938
|
use 5.008000; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
290
|
|
5
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
40
|
|
6
|
1
|
|
|
1
|
|
13178
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
155321
|
|
|
1
|
|
|
|
|
518
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Weather::Airport - Provides an interface to FlightStats.com Airport Weather Query |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Weather::Airport; |
17
|
|
|
|
|
|
|
my $wa = Weather::Airport->new; |
18
|
|
|
|
|
|
|
my $airport = $wa->query('LAX'); |
19
|
|
|
|
|
|
|
use Data::Dumper; |
20
|
|
|
|
|
|
|
print Dumper ($airport); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 new |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Creates Weather::Airport object. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new { |
33
|
0
|
|
|
0
|
1
|
|
my $self = bless({}, shift); |
34
|
0
|
|
|
|
|
|
my %args = @_; |
35
|
0
|
|
0
|
|
|
|
$self->{url} = $args{url} || 'http://www.flightstats.com/go/Airport/weather.do?airport='; |
36
|
0
|
|
0
|
|
|
|
$self->{referer} = $args{referer} || 'http://www.flightstats.com/go/Home/home.do'; |
37
|
0
|
|
0
|
|
|
|
$self->{uastring} = $args{uastring} || 'Weather::Airport/'.$VERSION; |
38
|
0
|
|
|
|
|
|
$self->{ua} = $args{ua}; # pass an existing LWP::UserAgent object |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
if (!$self->{ua}) |
41
|
|
|
|
|
|
|
{ |
42
|
0
|
|
|
|
|
|
$self->{ua} = LWP::UserAgent->new; |
43
|
0
|
|
|
|
|
|
$self->{ua}->agent($self->{uastring}); |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
return $self; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 query |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Queries the site. Provide an airport code to retrieve current conditions. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub query { |
55
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
56
|
0
|
|
|
|
|
|
my $apcode = shift; |
57
|
0
|
|
|
|
|
|
my @data; |
58
|
0
|
|
|
|
|
|
my $error = "The airport code is invalid."; |
59
|
0
|
|
|
|
|
|
$apcode =~ s/[^A-Za-z0-9]//g; |
60
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new(GET => $self->{url} . $apcode); |
61
|
0
|
0
|
|
|
|
|
$req->referer($self->{referer}) if $self->{referer}; |
62
|
0
|
|
|
|
|
|
$req->content_type('application/x-www-form-urlencoded'); |
63
|
0
|
|
|
|
|
|
my $res = $self->{ua}->request($req); |
64
|
0
|
0
|
|
|
|
|
if ($res->is_success) { |
65
|
0
|
|
|
|
|
|
my $content = $res->content; |
66
|
0
|
|
|
|
|
|
$content =~ s/\s+/ /g; |
67
|
0
|
0
|
|
|
|
|
if ($content =~ m#The airport code is invalid#) { |
68
|
0
|
|
|
|
|
|
return $error; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
else { |
71
|
0
|
|
|
|
|
|
while ($content =~ m/ |
(.*?)<\/tr>/g) { |
72
|
0
|
|
|
|
|
|
my $ap = ($1); |
73
|
0
|
|
|
|
|
|
$ap =~ s/<(.*?)>//gi; |
74
|
0
|
|
|
|
|
|
$ap =~ s/\ \;//gi; |
75
|
0
|
|
|
|
|
|
$ap =~ s/\°\;/�/gi; |
76
|
0
|
|
|
|
|
|
$ap =~ s/\s+/ /g; |
77
|
0
|
|
|
|
|
|
push(@data, "$ap"); |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
|
return \@data; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Copyright (C) 2010 Joseph Tartaro, Edroogie@foster.stonedcoder.orgE |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
91
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.10.0 or, |
92
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|