| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Weather::YR; | 
| 2 | 3 |  |  | 3 |  | 698807 | use Moose; | 
|  | 3 |  |  |  |  | 1396591 |  | 
|  | 3 |  |  |  |  | 17 |  | 
| 3 | 3 |  |  | 3 |  | 23824 | use namespace::autoclean; | 
|  | 3 |  |  |  |  | 20284 |  | 
|  | 3 |  |  |  |  | 16 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | extends 'Weather::YR::Base'; | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 3 |  |  | 3 |  | 1816 | use Weather::YR::LocationForecast; | 
|  | 3 |  |  |  |  | 15 |  | 
|  | 3 |  |  |  |  | 165 |  | 
| 8 | 3 |  |  | 3 |  | 1975 | use Weather::YR::TextLocation; | 
|  | 3 |  |  |  |  | 14 |  | 
|  | 3 |  |  |  |  | 678 |  | 
| 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.45. | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | =cut | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | our $VERSION = '0.45'; | 
| 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 |  | 8 | my $self = shift; | 
| 79 |  |  |  |  |  |  |  | 
| 80 | 2 |  |  |  |  | 17 | 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 |  |  |  |  |  |  | =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. |