lib/Weather/MOSMIX/Weathercodes.pm

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