Weather.pm

filter: Statementstmt 34.2% 13 / 38 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 100% 2 / 2 totaltotal 35.1% 19 / 54 CC 5 SCAR 27.5
CC
5
Cov
28%
said
30.0
help
2.0
BEGIN
1.0
CRAP 15.6
« Aviation.pm ↑ Summary
1 package Bot::BasicBot::Pluggable::Module::Weather;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Bot::BasicBot::Pluggable::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use base qw(Bot::BasicBot::Pluggable::Module);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Geo::WeatherNWS;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 0 ▶sub said {
Subroutine said: not called CC=5 SCAR=34.0
Pod documented
10 0 my ($self, $mess, $pri) = @_;
11  
12 0 my $body = $mess->{body};
13 0 my $who = $mess->{who};
14  
15 0 ▶ return unless ($pri == 2);
Branch: 1 branch
BranchTrueFalseTotal
unless $pri == 2 0 0 0
16 0 ▶ return unless $body =~ /^\s*weather\s+(?:for\s+)?(.*?)\s*\?*\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $body =~ /^\s*weather\s+(?:for\s+)?(.*?)\s*\?*\s*$/ 0 0 0
17 0 my $code = $1;
18  
19 0 ▶ return "Try a 4-letter station code (see http://weather.noaa.gov/weather/curcond.html for locations and codes)"
Branch: 1 branch
BranchTrueFalseTotal
unless $code =~ /^[a-zA-Z][a-zA-Z0-9]{3,4}$/ 0 0 0
20 unless $code =~ /^[a-zA-Z][a-zA-Z0-9]{3,4}$/;
21  
22 0 my $w = Geo::WeatherNWS->new();
23  
24 0 my $r = $w->getreport($code);
25  
26 return "There was an error - ".$r->{errortext}
27 0 ▶ if $r->{error} != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"error"} != 0 0 0 0
28  
29 0 my $response = "";
30  
31 0 my $time = $r->{time};
32  
33 0 $time = s!(\d\d)$!:$1!;
34  
35 0 $response .= sprintf "(%s) Conditions at %d; ", $code, $time;
36 0 $response .= sprintf "Dewpoint: %d F (%d C); ", $r->{dewpoint_f}, $r->{dewpoint_c};
37 0 $response .= sprintf "Pressure (altimeter): %d in. Hg (%d hPa); ", $r->{pressure_inhg}, $r->{pressure_mb};
38 0 $response .= sprintf "Relative Humidity: %d%%; ", $r->{relative_humidity};
39 0 $response .= sprintf "Sky conditions: %s; ", $r->{conditionstext};
40 0 $response .= sprintf "Temperature: %d C (%d F);", $r->{temperature_c}, $r->{temperature_f};
41 0 $response .= sprintf "Visibility: %d mile(s) (%d km); ", $r->{visibility_mi}, $r->{visibility_km};
42 0 $response .= sprintf "Wind: from the %s (%d degrees) ", $r->{winddirtext}, $r->{winddir};
43 0 $response .= sprintf "at %d MPH (%d KT) gusting ", $r->{windspeedmph}, $r->{windspeedkts};
44 0 $response .= sprintf "to %d MPH (%d KT)", $r->{windgustmph}, $r->{windgustkts};
45  
46 0 return $response;
47  
48 }
49  
50 0 ▶sub help {
Subroutine help: not called CC=1 SCAR=6.9
Pod documented
51 0 return "Commands: 'yow' or 'be zippy'";
52 }
53  
54 1 1;
55  
56 =head1 NAME
57  
58 Bot::BasicBot::Pluggable::Module::Weather - get the weather forcast from NOAA
59  
60 =head1 SYNOPSIS
61  
62 Contacts C<weather.noaa.gov> and gets the weather report for a given
63 station.
64  
65 =head1 IRC USAGE
66  
67 weather [for] <station>
68  
69  
70 =head1 AUTHOR
71  
72 Simon Wistow, <simon@thegestalt.org>
73  
74 based on code by Kevin Lenzo <lenzo@cs.cmu.edu>
75  
76 =head1 COPYRIGHT
77  
78 Copyright 2005, Simon Wistow
79  
80 Distributed under the same terms as Perl itself.
81  
82 =head1 SEE ALSO
83  
84  
85 =cut
86  
« Aviation.pm ↑ Summary