line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Acme::Test::Weather - Test the weather conditions for a user. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Test::Weather; |
8
|
|
|
|
|
|
|
plan tests => 2; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# You may only install something |
11
|
|
|
|
|
|
|
# when it's nice outside. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
&isnt_snowing(); |
14
|
|
|
|
|
|
|
&isnt_cloudy(); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# output: |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
1..2 |
19
|
|
|
|
|
|
|
ok 1 - it's partly cloudy in Montreal, Canada |
20
|
|
|
|
|
|
|
not ok 2 - it's partly cloudy in Montreal, Canada |
21
|
|
|
|
|
|
|
# Failed test (./t/mtl.t at line 5) |
22
|
|
|
|
|
|
|
# 'Partly Cloudy' |
23
|
|
|
|
|
|
|
# matches '(?i-xsm:\bcloudy)' |
24
|
|
|
|
|
|
|
# Looks like you failed 1 tests of 2. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Test the weather conditions for a user. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
The package determines a user's location by looking up their hostname / |
31
|
|
|
|
|
|
|
IP address using the I package. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Based on the data returned, weather conditions are polled using the |
34
|
|
|
|
|
|
|
I package. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Because, you know, it may be important to your Perl module that it's |
37
|
|
|
|
|
|
|
raining outside... |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
1
|
|
1116
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
62
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
package Acme::Test::Weather; |
44
|
1
|
|
|
1
|
|
7
|
use base qw (Exporter); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
146
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$Acme::Test::Weather::VERSION = '0.2'; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
@Acme::Test::Weather::EXPORT = qw (plan |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
is_sunny isnt_sunny |
51
|
|
|
|
|
|
|
is_cloudy isnt_cloudy |
52
|
|
|
|
|
|
|
is_snowing isnt_snowing |
53
|
|
|
|
|
|
|
is_raining isnt_raining |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
eq_celsius lt_celsius gt_celsius |
56
|
|
|
|
|
|
|
eq_fahrenheit lt_fahrenheit gt_fahrenheit |
57
|
|
|
|
|
|
|
eq_humidity lt_humidity gt_humidity |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
1
|
|
28
|
use Test::Builder; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
1
|
|
942
|
use Sys::Hostname; |
|
1
|
|
|
|
|
1943
|
|
|
1
|
|
|
|
|
56
|
|
65
|
1
|
|
|
1
|
|
1072
|
use Socket; |
|
1
|
|
|
|
|
5419
|
|
|
1
|
|
|
|
|
718
|
|
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
1
|
|
518
|
use CAIDA::NetGeoClient; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
use Geography::Countries; |
69
|
|
|
|
|
|
|
use Weather::Underground; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $addr = gethostbyname(hostname); |
72
|
|
|
|
|
|
|
my $ip = inet_ntoa($addr); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $test = Test::Builder->new(); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $geo = CAIDA::NetGeoClient->new(); |
77
|
|
|
|
|
|
|
my $record = $geo->getRecord($ip); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $city = ucfirst(lc($record->{CITY})); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# If city is in the States use the state as |
82
|
|
|
|
|
|
|
# the region. Otherwise use Geography::Countries |
83
|
|
|
|
|
|
|
# to munge the two letter code for the country |
84
|
|
|
|
|
|
|
# into its actual name. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# Because things like 'Cambridge, US' cause |
87
|
|
|
|
|
|
|
# wunderground.com to spazz out :-( |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $region = ($record->{COUNTRY} eq "US") ? |
90
|
|
|
|
|
|
|
ucfirst(lc($record->{STATE})) : country($record->{COUNTRY}); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $place = "$city, $region"; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $weather = Weather::Underground->new(place => $place); |
95
|
|
|
|
|
|
|
my $data = $weather->getweather()->[0]; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
#use Data::Denter; |
98
|
|
|
|
|
|
|
#print Indent($data); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 PACKAGE FUNCTIONS |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 &is_cloudy() |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Make sure it is cloudy, but remember the silver lining. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub is_cloudy { |
111
|
|
|
|
|
|
|
$test->like($data->{conditions},qr/\b(cloudy|overcast)/i,&_conditions()); |
112
|
|
|
|
|
|
|
}; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 &isnt_cloudy() |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
No clouds. Not even little fluffy ones. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub isnt_cloudy { |
121
|
|
|
|
|
|
|
$test->unlike($data->{conditions},qr/\b(cloudy|overcast)/i,&_conditions()); |
122
|
|
|
|
|
|
|
}; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 &is_raining() |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Make sure it is raining. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub is_raining { |
131
|
|
|
|
|
|
|
$test->like($data->{conditions},qr/\brain/i,&_conditions()); |
132
|
|
|
|
|
|
|
}; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 &isnt_raining() |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Make sure sure it is not raining. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub isnt_raining { |
141
|
|
|
|
|
|
|
$test->unlike($data->{conditions},qr/\brain/i,&_conditions()); |
142
|
|
|
|
|
|
|
}; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 &is_snowing() |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Make sure it is snowing. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub is_snowing { |
151
|
|
|
|
|
|
|
$test->like($data->{conditions},qr/\bsnow/i,&_conditions()); |
152
|
|
|
|
|
|
|
}; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 &isnt_snowing() |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Make sure it is not snowing. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub isnt_snowing { |
161
|
|
|
|
|
|
|
$test->unlike($data->{conditions},qr/\bsnow/i,&_conditions()); |
162
|
|
|
|
|
|
|
}; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 &is_sunny() |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Make sure it is sunny. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub is_sunny { |
171
|
|
|
|
|
|
|
$test->like($data->{conditions},qr/\bsun/i,&_conditions()); |
172
|
|
|
|
|
|
|
}; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 &isnt_sunny() |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Make sure it is not sunny. Why are you so angry? |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub isnt_sunny { |
181
|
|
|
|
|
|
|
$test->unlike($data->{conditions},qr/\bsun/i,&_conditions()); |
182
|
|
|
|
|
|
|
}; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 &eq_celsius($int) |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Temperature in degrees Celsius. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub eq_celsius { |
191
|
|
|
|
|
|
|
$test->cmp_ok($data->{celsius},"==",$_[0],&_temp("celsius")); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 >_celsius($int) |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Cooler than, in degrees Celcius. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub gt_celsius { |
201
|
|
|
|
|
|
|
$test->cmp_ok($data->{celsius},">",$_[0],&_temp("celsius")); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 <_celsius($int) |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Warmer than, in degrees Celsius. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub lt_celsius { |
211
|
|
|
|
|
|
|
$test->cmp_ok($data->{celsius},"<",$_[0],&_temp("celsius")); |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head2 &eq_fahrenheit($int) |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Temperature, in degrees Fahrenheit. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=cut |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub eq_fahrenheit { |
221
|
|
|
|
|
|
|
$test->cmp_ok($data->{fahrenheit},"==",$_[0],&_temp("fahrenheit")); |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head2 >_fahrenheit($int) |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Warmer than, in degrees Fahrenheit. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=cut |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
sub gt_fahrenheit { |
231
|
|
|
|
|
|
|
$test->cmp_ok($data->{fahrenheit},">",$_[0],&_temp("fahrenheit")); |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head2 <_fahrenheit($int) |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Cooler than, in degrees Fahrenheit. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=cut |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub lt_fahrenheit { |
241
|
|
|
|
|
|
|
$test->cmp_ok($data->{fahrenheit},"<",$_[0],&_temp("fahrenheit")); |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head2 &eq_humidity($int) |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
Humidity. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=cut |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub eq_humidity { |
251
|
|
|
|
|
|
|
$test->cmp_ok($data->{humidity},"==",$_[0],&_humidity()); |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head2 >_humidity($int) |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Humidity is greater than. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=cut |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
sub gt_humidity { |
261
|
|
|
|
|
|
|
$test->cmp_ok($data->{humidity},">",$_[0],&_humidity()); |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=head2 <_humidity($int) |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
Humidity is less than. |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=cut |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
sub lt_humidity { |
271
|
|
|
|
|
|
|
$test->cmp_ok($data->{humidity},"<",$_[0],&_humidity()); |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
sub _conditions { return "it's ".lc($data->{conditions})." in $place"; } |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
sub _humidity { return "the humidity in $place is $data->{humidity}"; } |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
sub _temp { my $m = shift; return "it $data->{$m} degrees $m in $place"; } |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
# Stuff I, ahem, borrowed from Test::More |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
sub plan { |
283
|
|
|
|
|
|
|
my(@plan) = @_; |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
my $caller = caller; |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
$test->exported_to($caller); |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
my @imports = (); |
290
|
|
|
|
|
|
|
foreach my $idx (0..$#plan) { |
291
|
|
|
|
|
|
|
if( $plan[$idx] eq 'import' ) { |
292
|
|
|
|
|
|
|
my($tag, $imports) = splice @plan, $idx, 2; |
293
|
|
|
|
|
|
|
@imports = @$imports; |
294
|
|
|
|
|
|
|
last; |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
$test->plan(@plan); |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
__PACKAGE__->_export_to_level(1, __PACKAGE__, @imports); |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
sub _export_to_level |
304
|
|
|
|
|
|
|
{ |
305
|
|
|
|
|
|
|
my $pkg = shift; |
306
|
|
|
|
|
|
|
my $level = shift; |
307
|
|
|
|
|
|
|
(undef) = shift; # redundant arg |
308
|
|
|
|
|
|
|
my $callpkg = caller($level); |
309
|
|
|
|
|
|
|
$pkg->export($callpkg, @_); |
310
|
|
|
|
|
|
|
} |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
=head1 VERSION |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
0.2 |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
=head1 DATE |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
$Date: 2003/02/21 19:25:34 $ |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
=head1 AUTHOR |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
Aaron Straup Cope |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
=head1 SEE ALSO |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
http://www.caida.org/tools/utilities/netgeo/NGAPI/index.xml |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
L |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
http://search.cpan.org/dist/Acme |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
=head1 SHOUT-OUTS |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
It's all Kellan's fault. |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
=head1 BUGS |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
Not hard to imagine. |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
Please report all bugs via http://rt.cpan.org |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
=head1 LICENSE |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
Copyright (c) 2003, Aaron Straup Cope. All Rights Reserved. |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
This is free software, you may use it and distribute it under the same terms as Perl itself |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
=cut |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
return 1; |
351
|
|
|
|
|
|
|
|