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.03';
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 '68' => { emoji => "\N{CLOUD WITH SNOW}", svg => 'snow.svg', text => 'slight rain and snow' },
33 '80' => { emoji => "\N{CLOUD WITH RAIN}", svg => 'day-light-rain.svg',
34 text => 'light rain' }, # light rain
35 '81' => { emoji => "\N{RAIN}", svg => 'day-rain.svg' }, # medium rain
36 '82' => { emoji => "\N{RAIN}", svg => 'day-showers.svg' }, # strong rain
37 '83' => { emoji => "\N{CLOUD WITH SNOW}", svg => 'snow.svg', text => 'showers of rain and snow mixed, slight' },
38 '95' => { emoji => "\N{CLOUD WITH LIGHTNING}", svg => 'thundershowers.svg',
39 text => 'slight or moderate thunderstorm with rain or snow'
40 },
41 );
42  
43 # alternatives
44 # 🌣 U1f323 \N{WHITE SUN}
45 # 🌤 U1f324 \N{WHITE SUN WITH SMALL CLOUD}
46 # 🌥 U1f325 \N{WHITE SUN BEHIND CLOUD}
47 # 🌦 U1f326 \N{WHITE SUN BEHIND CLOUD WITH RAIN}
48 # 🌪 U1f32a \N{CLOUD WITH TORNADO}
49  
50 0 ▶sub mosmix_weathercode($code, $type = undef) {
Subroutine mosmix_weathercode: not called CC=6 SCAR=37.4
Pod documented
51 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
52 0 ▶ if( $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) { } 0 0 0
53 0 my $c = $weathercodes{$code}->{ $type };
54 0 ▶ return $c ? $c . $as_emoji : $code;
Branch: 1 branch
BranchTrueFalseTotal
$c ? : 0 0 0
55 } else {
56 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
57 0 return $weathercodes{ $code }
58 }
59 }
60  
61 3 1;
62  
63 =head1 NAME
64  
65 Weather::MOSMIX::Weathercodes - weather codes for MOSMIX data
66  
67 =head1 SYNOPSIS
68  
69 use Weather::MOSMIX::Weathercodes 'mosmix_weathercode';
70 print mosmix_weathercode('01')->{text}; # sunny
71 print mosmix_weathercode('01')->{emoji}; # \N{SUN} emoji
72  
73 =head1 FUNCTIONS
74  
75 =head2 C<< mosmix_weathercode >>
76  
77 my $c = mosmix_weathercode('01');
78  
79 This function returns a reference to a hash of items representing a
80 weather code. The hash keys are:
81  
82 =over 4
83  
84 =item B<<emoji>>
85  
86 Emoji representing this weather code
87  
88 =item B<<svg>>
89  
90 SVG filename representing this weather code, taken from the Tempestacons
91  
92 =item B<<text>>
93  
94 English text description as provided by DWD
95  
96 =back
97  
98 =head1 SEE ALSO
99  
100 L<https://www.dwd.de/DE/leistungen/opendata/help/schluessel_datenformate/kml/mosmix_element_weather_xls.html>
101  
102 L<Tempestacons|https://github.com/zagortenay333/Tempestacons/>
103  
104 =head1 REPOSITORY
105  
106 The public repository of this module is
107 L<https://github.com/Corion/weather-mosmix>.
108  
109 =head1 SUPPORT
110  
111 The public support forum of this module is L<https://perlmonks.org/>.
112  
113 =head1 BUG TRACKER
114  
115 Please report bugs in this module via the RT CPAN bug queue at
116 L<https://rt.cpan.org/Public/Dist/Display.html?Name=Weather-MOSMIX>
117 or via mail to L<www-Weather-MOSMIX@rt.cpan.org|mailto:Weather-MOSMIX@rt.cpan.org>.
118  
119 =head1 AUTHOR
120  
121 Max Maischein C<corion@cpan.org>
122  
123 =head1 COPYRIGHT (c)
124  
125 Copyright 2019-2020 by Max Maischein C<corion@cpan.org>.
126  
127 =head1 LICENSE
128  
129 This module is released under the same terms as Perl itself.
130  
131 =cut
« Makefile.PL ↑ Summary blib/lib/Weather/MOSMIX.pm »