YR.pm

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