line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Weather::YR; |
2
|
3
|
|
|
3
|
|
735347
|
use Moose; |
|
3
|
|
|
|
|
1517390
|
|
|
3
|
|
|
|
|
18
|
|
3
|
3
|
|
|
3
|
|
25400
|
use namespace::autoclean; |
|
3
|
|
|
|
|
24163
|
|
|
3
|
|
|
|
|
20
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
extends 'Weather::YR::Base'; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
2629
|
use Weather::YR::LocationForecast; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
156
|
|
8
|
3
|
|
|
3
|
|
2854
|
use Weather::YR::TextLocation; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
599
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Weather::YR - Object-oriented interface to Yr.no's weather service. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Version 0.44. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.44'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Weather::YR; |
25
|
|
|
|
|
|
|
use DateTime::TimeZone; |
26
|
|
|
|
|
|
|
use LWP::UserAgent; |
27
|
|
|
|
|
|
|
use feature 'say'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $yr = Weather::YR->new( |
30
|
|
|
|
|
|
|
lang => 'en', |
31
|
|
|
|
|
|
|
lat => 63.5908, |
32
|
|
|
|
|
|
|
lon => 10.7414, |
33
|
|
|
|
|
|
|
tz => DateTime::TimeZone->new( name => 'Europe/Oslo' ), |
34
|
|
|
|
|
|
|
ua => LWP::UserAgent->new( |
35
|
|
|
|
|
|
|
agent => 'AcmeWeatherApp/0.9 support@example.com', |
36
|
|
|
|
|
|
|
), |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
foreach my $day ( @{$yr->location_forecast->days} ) { |
40
|
|
|
|
|
|
|
say 'Weather data for ' . $day->date->ymd . ':'; |
41
|
|
|
|
|
|
|
say ' ' x 4 . 'Temperature @ ' . $day->temperature->from->hms . ': ' . $day->temperature->celsius; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
foreach my $dp ( @{$day->datapoints} ) { |
44
|
|
|
|
|
|
|
say ' ' x 4 . 'Wind direction @ ' . $dp->wind_direction->from->hms . ': ' . $dp->wind_direction->name; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# If you are interested in the weather right now (*): |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $now = $yr->location_forecast->now; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
say "It's " . $now->temperature->celsius . "C outside."; |
53
|
|
|
|
|
|
|
say "Weather status: " . $now->precipitation->symbol->text; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# (*) "Right now" is actually lying, as the data from Yr is always |
56
|
|
|
|
|
|
|
# a _forecast_, ie. what the weather will be like. The now() |
57
|
|
|
|
|
|
|
# method simply picks the closest data point in time. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 DESCRIPTION |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
This is an object-oriented interface to Yr.no's free weather service located at |
62
|
|
|
|
|
|
|
L<https://api.met.no/>. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
has 'location_forecast' => ( isa => 'Weather::YR::LocationForecast', is => 'ro', lazy_build => 1 ); |
67
|
|
|
|
|
|
|
# has 'text_location' => ( isa => 'Weather::YR::TextLocation', is => 'ro', lazy_build => 1 ); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 METHODS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 location_forecast |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Returns a L<Weather::YR::LocationForecast> instance. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _build_location_forecast { |
78
|
2
|
|
|
2
|
|
5
|
my $self = shift; |
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
65
|
return Weather::YR::LocationForecast->new( |
81
|
|
|
|
|
|
|
lat => $self->lat, |
82
|
|
|
|
|
|
|
lon => $self->lon, |
83
|
|
|
|
|
|
|
msl => $self->msl, |
84
|
|
|
|
|
|
|
xml => $self->xml, |
85
|
|
|
|
|
|
|
lang => $self->lang, |
86
|
|
|
|
|
|
|
tz => $self->tz, |
87
|
|
|
|
|
|
|
ua => $self->ua, |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# sub _build_text_location { |
92
|
|
|
|
|
|
|
# my $self = shift; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# return Weather::YR::TextLocation->new( |
95
|
|
|
|
|
|
|
# lat => $self->lat, |
96
|
|
|
|
|
|
|
# lon => $self->lon, |
97
|
|
|
|
|
|
|
# lang => $self->lang, |
98
|
|
|
|
|
|
|
# ); |
99
|
|
|
|
|
|
|
# } |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 TODO |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=over 4 |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item * Improve the documentation. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item * Add more tests. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item * Add support for more of Yr.no's APIs. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item * Translate wind speed names/descriptions. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=back |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 BUGS |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Please report any bugs or feature requests via the web interface at |
122
|
|
|
|
|
|
|
L<https://rt.cpan.org/Public/Dist/Display.html?Name=Weather-YR>, or via |
123
|
|
|
|
|
|
|
the github interface at L<https://github.com/toreau/Weather-YR/issues>. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 AUTHORS |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=over 4 |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item * Tore Aursand, 2014-2021, C<< toreau@gmail.com >> |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item * Knut-Olav Hoven, 2008-2013, C<< knut-olav@hoven.ws >> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=back |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=over 4 |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item * Andreas Vögele |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=back |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Copyright 2014-2021, Tore Aursand. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
148
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
149
|
|
|
|
|
|
|
copy of the full license at: |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
L<http://www.perlfoundation.org/artistic_license_2_0> |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
154
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
155
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
156
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
159
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
160
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
163
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
166
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
167
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
168
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
169
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
170
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
171
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
172
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
175
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
176
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
177
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
178
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
179
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
180
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
181
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |