blib/lib/Weather/MOSMIX/Weathercodes.pm

filter: Statementstmt 76.6% 23 / 30 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 62.5% 30 / 48 CC 6 SCAR 30.7
CC
6
Cov
61%
mosmix_weathercode
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 21.5
« Makefile.PL ↑ Summary blib/lib/Weather/MOSMIX.pm »
1 package Weather::MOSMIX::Weathercodes;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use Filter::signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶no warnings 'experimental::signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our @EXPORT_OK = 'mosmix_weathercode';
10  
11 3 our $VERSION = '0.02';
12  
13 3 our $as_emoji = "\x{fe0f}";
14  
15 3 our %weathercodes = (
16 # Should we separate these into day/night ?!
17 # We should add the textual description, even if only to translate that later on
18 3 ▶ '00' => { emoji => "\N{SUN}", svg => 'day.svg',
Subroutine BEGIN: called CC=1 SCAR=0.0
19 text => 'sunny' },
20 '01' => { emoji => "\N{WHITE SUN WITH SMALL CLOUD}", svg => 'day-partly-cloudy.svg',
21 text => 'mostly sunny', },
22 '02' => { emoji => "\N{WHITE SUN WITH SMALL CLOUD}", svg => 'day-partly-cloudy.svg',
23 text => 'partly cloudy', },
24 '03' => { emoji => "\N{SUN BEHIND CLOUD}", svg => 'day-cloudy.svg',
25 text => 'mostly cloudy' },
26 '04' => { emoji => "\N{CLOUD}", svg => 'day-cloudy.svg',
27 text => 'overcast' },
28 '45' => { emoji => "\N{FOG}", svg => 'fog.svg' },
29 '49' => { emoji => "\N{FOG}", svg => 'fog.svg' },
30 '61' => { emoji => "\N{CLOUD WITH RAIN}", svg => 'rain.svg', text => 'slight rain, not freezing, continuous' },
31 '63' => { emoji => "\N{CLOUD WITH RAIN}", svg => 'rain.svg' },
32 '80' => { emoji => "\N{CLOUD WITH RAIN}", svg => 'day-light-rain.svg',
33 text => 'light rain' }, # light rain
34 '81' => { emoji => "\N{RAIN}", svg => 'day-rain.svg' }, # medium rain
35 '82' => { emoji => "\N{RAIN}", svg => 'day-showers.svg' }, # strong rain
36 '95' => { emoji => "\N{RAIN}", svg => 'thundershowers.svg',
37 text => 'slight or moderate thunderstorm with rain or snow'
38 },
39 );
40  
41 0 ▶sub mosmix_weathercode($code, $type = undef) {
Subroutine mosmix_weathercode: not called CC=6 SCAR=37.4
Pod documented
42 0 ▶ $code = sprintf '%02d', $code || 0;
Condition0%0/2
$code || 0
l!l
00
MC/DC0%0/1
$code || 0
$code
Truth table0%0/2
A
A= $code
Aresult
11
00
43 0 ▶ if( $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) { } 0 0 0
44 0 my $c = $weathercodes{$code}->{ $type };
45 0 ▶ return $c ? $c . $as_emoji : $code;
Branch: 1 branch
BranchTrueFalseTotal
$c ? : 0 0 0
46 } else {
47 0 ▶ $weathercodes{ $code }->{ text } ||= "??? $code";
Condition0%0/2
$Weather::MOSMIX::Weathercodes::weathercodes{$code}{"text"} ||= "??? $code"
l!l
00
MC/DC0%0/1
$Weather::MOSMIX::Weathercodes::weathercodes{$code}{"text"} ||= "??? $code"
$Weather::MOSMIX::Weathercodes::weathercodes{$code}{"text"}
Truth table0%0/2
A
A= $Weather::MOSMIX::Weathercodes::weathercodes{$code}{"text"}
Aresult
11
00
48 0 return $weathercodes{ $code }
49 }
50 }
51  
52 3 1;
53  
54 =head1 NAME
55  
56 Weather::MOSMIX::Weathercodes - weather codes for MOSMIX data
57  
58 =head1 SYNOPSIS
59  
60 use Weather::MOSMIX::Weathercodes 'mosmix_weathercode';
61 print mosmix_weathercode('01')->{text}; # sunny
62 print mosmix_weathercode('01')->{emoji}; # \N{SUN} emoji
63  
64 =head1 FUNCTIONS
65  
66 =head2 C<< mosmix_weathercode >>
67  
68 my $c = mosmix_weathercode('01');
69  
70 This function returns a reference to a hash of items representing a
71 weather code. The hash keys are:
72  
73 =over 4
74  
75 =item B<<emoji>>
76  
77 Emoji representing this weather code
78  
79 =item B<<svg>>
80  
81 SVG filename representing this weather code, taken from the Tempestacons
82  
83 =item B<<text>>
84  
85 English text description as provided by DWD
86  
87 =back
88  
89 =head1 SEE ALSO
90  
91 L<https://www.dwd.de/DE/leistungen/opendata/help/schluessel_datenformate/kml/mosmix_element_weather_xls.html>
92  
93 L<Tempestacons|https://github.com/zagortenay333/Tempestacons/>
94  
95 =head1 REPOSITORY
96  
97 The public repository of this module is
98 L<https://github.com/Corion/weather-mosmix>.
99  
100 =head1 SUPPORT
101  
102 The public support forum of this module is L<https://perlmonks.org/>.
103  
104 =head1 BUG TRACKER
105  
106 Please report bugs in this module via the RT CPAN bug queue at
107 L<https://rt.cpan.org/Public/Dist/Display.html?Name=Weather-MOSMIX>
108 or via mail to L<www-Weather-MOSMIX@rt.cpan.org|mailto:Weather-MOSMIX@rt.cpan.org>.
109  
110 =head1 AUTHOR
111  
112 Max Maischein C<corion@cpan.org>
113  
114 =head1 COPYRIGHT (c)
115  
116 Copyright 2019-2020 by Max Maischein C<corion@cpan.org>.
117  
118 =head1 LICENSE
119  
120 This module is released under the same terms as Perl itself.
121  
122 =cut
« Makefile.PL ↑ Summary blib/lib/Weather/MOSMIX.pm »