| 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.38. | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | 3 | our $VERSION = '0.38'; | |
| 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->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 data point 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<https://api.met.no/>. | ||
| 57 | |||
| 58 | =cut | ||
| 59 | |||
| 60 | 3 | 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 | 2 | ▶ | my $self = shift; |
|
Subroutine
_build_location_forecast: called CC=1 SCAR=0.0
| |||
| 73 | |||
| 74 | 2 | 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 | ua => $self->ua, | ||
| 82 | ); | ||
| 83 | } | ||
| 84 | |||
| 85 | # sub _build_text_location { | ||
| 86 | # my $self = shift; | ||
| 87 | |||
| 88 | # return Weather::YR::TextLocation->new( | ||
| 89 | # lat => $self->lat, | ||
| 90 | # lon => $self->lon, | ||
| 91 | # lang => $self->lang, | ||
| 92 | # ); | ||
| 93 | # } | ||
| 94 | |||
| 95 | 3 | __PACKAGE__->meta->make_immutable; | |
| 96 | |||
| 97 | 3 | 1; | |
| 98 | |||
| 99 | =head1 TODO | ||
| 100 | |||
| 101 | =over 4 | ||
| 102 | |||
| 103 | =item * Improve the documentation. | ||
| 104 | |||
| 105 | =item * Add more tests. | ||
| 106 | |||
| 107 | =item * Add support for more of Yr.no's APIs. | ||
| 108 | |||
| 109 | =item * Translate wind speed names/descriptions. | ||
| 110 | |||
| 111 | =back | ||
| 112 | |||
| 113 | =head1 BUGS | ||
| 114 | |||
| 115 | Please report any bugs or feature requests via the web interface at | ||
| 116 | L<https://rt.cpan.org/Public/Dist/Display.html?Name=Weather-YR>, or via | ||
| 117 | the github interface at L<https://github.com/toreau/Weather-YR/issues>. | ||
| 118 | |||
| 119 | =head1 AUTHORS | ||
| 120 | |||
| 121 | =over 4 | ||
| 122 | |||
| 123 | =item * Tore Aursand, 2014-2016, C<< toreau@gmail.com >> | ||
| 124 | |||
| 125 | =item * Knut-Olav Hoven, 2008-2014, C<< knut-olav@hoven.ws >> | ||
| 126 | |||
| 127 | =back | ||
| 128 | |||
| 129 | =head1 LICENSE AND COPYRIGHT | ||
| 130 | |||
| 131 | Copyright 2014-2016, ABC Startsiden. | ||
| 132 | |||
| 133 | This program is free software; you can redistribute it and/or modify it | ||
| 134 | under the terms of the the Artistic License (2.0). You may obtain a | ||
| 135 | copy of the full license at: | ||
| 136 | |||
| 137 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||
| 138 | |||
| 139 | Any use, modification, and distribution of the Standard or Modified | ||
| 140 | Versions is governed by this Artistic License. By using, modifying or | ||
| 141 | distributing the Package, you accept this license. Do not use, modify, | ||
| 142 | or distribute the Package, if you do not accept this license. | ||
| 143 | |||
| 144 | If your Modified Version has been derived from a Modified Version made | ||
| 145 | by someone other than you, you are nevertheless required to ensure that | ||
| 146 | your Modified Version complies with the requirements of this license. | ||
| 147 | |||
| 148 | This license does not grant you the right to use any trademark, service | ||
| 149 | mark, tradename, or logo of the Copyright Holder. | ||
| 150 | |||
| 151 | This license includes the non-exclusive, worldwide, free-of-charge | ||
| 152 | patent license to make, have made, use, offer to sell, sell, import and | ||
| 153 | otherwise transfer the Package with respect to any patent claims | ||
| 154 | licensable by the Copyright Holder that are necessarily infringed by the | ||
| 155 | Package. If you institute patent litigation (including a cross-claim or | ||
| 156 | counterclaim) against any party alleging that the Package constitutes | ||
| 157 | direct or contributory patent infringement, then this Artistic License | ||
| 158 | to you shall terminate on the date that such litigation is filed. | ||
| 159 | |||
| 160 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||
| 161 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||
| 162 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
| 163 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||
| 164 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||
| 165 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||
| 166 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||
| 167 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||