| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Weather::YR::Base; |
|
2
|
3
|
|
|
3
|
|
1768
|
use Moose; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
18
|
|
|
3
|
3
|
|
|
3
|
|
16508
|
use namespace::autoclean; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
26
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
209
|
use DateTime::Format::ISO8601; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
79
|
|
|
6
|
3
|
|
|
3
|
|
16
|
use DateTime::TimeZone; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
70
|
|
|
7
|
3
|
|
|
3
|
|
13
|
use DateTime; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
48
|
|
|
8
|
3
|
|
|
3
|
|
6745244
|
use LWP::UserAgent; |
|
|
3
|
|
|
|
|
8947667
|
|
|
|
3
|
|
|
|
|
126
|
|
|
9
|
3
|
|
|
3
|
|
2399
|
use XML::Bare; |
|
|
3
|
|
|
|
|
46968
|
|
|
|
3
|
|
|
|
|
223
|
|
|
10
|
3
|
|
|
3
|
|
669
|
use XML::LibXML; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has [ 'lat', 'lon', 'msl' ] => ( |
|
13
|
|
|
|
|
|
|
isa => 'Maybe[Num]', |
|
14
|
|
|
|
|
|
|
is => 'rw', |
|
15
|
|
|
|
|
|
|
required => 0, |
|
16
|
|
|
|
|
|
|
default => 0, |
|
17
|
|
|
|
|
|
|
); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has 'xml' => ( |
|
20
|
|
|
|
|
|
|
isa => 'Maybe[Str]', |
|
21
|
|
|
|
|
|
|
is => 'rw', |
|
22
|
|
|
|
|
|
|
required => 0, |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has 'lang' => ( |
|
26
|
|
|
|
|
|
|
isa => 'Maybe[Str]', |
|
27
|
|
|
|
|
|
|
is => 'rw', |
|
28
|
|
|
|
|
|
|
required => 0, |
|
29
|
|
|
|
|
|
|
default => 'nb', |
|
30
|
|
|
|
|
|
|
); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has 'tz' => ( |
|
33
|
|
|
|
|
|
|
isa => 'DateTime::TimeZone', |
|
34
|
|
|
|
|
|
|
is => 'rw', |
|
35
|
|
|
|
|
|
|
required => 0, |
|
36
|
|
|
|
|
|
|
default => sub { DateTime::TimeZone->new( name => 'UTC' ); }, |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has 'ua' => ( |
|
40
|
|
|
|
|
|
|
isa => 'Object', |
|
41
|
|
|
|
|
|
|
is => 'rw', |
|
42
|
|
|
|
|
|
|
required => 0, |
|
43
|
|
|
|
|
|
|
default => sub { LWP::UserAgent->new; }, |
|
44
|
|
|
|
|
|
|
); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has 'xml_ref' => ( |
|
47
|
|
|
|
|
|
|
isa => 'Maybe[HashRef]', |
|
48
|
|
|
|
|
|
|
is => 'ro', |
|
49
|
|
|
|
|
|
|
lazy_build => 1, |
|
50
|
|
|
|
|
|
|
); |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _build_xml_ref { |
|
53
|
|
|
|
|
|
|
my $self = shift; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
unless ( length $self->xml ) { |
|
56
|
|
|
|
|
|
|
my $response = $self->ua->get( $self->url ); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
if ( $self->can('status_code') ) { |
|
59
|
|
|
|
|
|
|
$self->status_code( $response->code ); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
if ( $response->is_success ) { |
|
63
|
|
|
|
|
|
|
$self->xml( $response->decoded_content ); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
if ( length $self->xml ) { |
|
68
|
|
|
|
|
|
|
if ( $self->can('schema_url') ) { |
|
69
|
|
|
|
|
|
|
eval { |
|
70
|
|
|
|
|
|
|
my $xml_doc = XML::LibXML->new->load_xml( string => $self->xml ); |
|
71
|
|
|
|
|
|
|
my $schema = XML::LibXML::Schema->new( location => $self->schema_url ); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$schema->validate( $xml_doc ); |
|
74
|
|
|
|
|
|
|
}; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
if ( $@ ) { |
|
77
|
|
|
|
|
|
|
warn "Failed to validate the XML returned from YR.no using schema URL '" . $self->schema_url . "'; $@"; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
else { |
|
80
|
|
|
|
|
|
|
my $result = undef; |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
eval { |
|
83
|
|
|
|
|
|
|
$result = XML::Bare->new( text => $self->xml )->parse; |
|
84
|
|
|
|
|
|
|
}; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
unless ( $@ ) { |
|
87
|
|
|
|
|
|
|
return $result; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Something failed! |
|
95
|
|
|
|
|
|
|
return undef; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub date_to_datetime { |
|
99
|
|
|
|
|
|
|
my $self = shift; |
|
100
|
|
|
|
|
|
|
my $date = shift // ''; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
if ( length $date ) { |
|
103
|
|
|
|
|
|
|
$date = DateTime::Format::ISO8601->parse_datetime( $date ); |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
else { |
|
106
|
|
|
|
|
|
|
$date = DateTime->now; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$date->set_time_zone( $self->tz ); |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
return $date; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |