File Coverage

blib/lib/Weather/YR.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


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