This file is indexed.

/usr/share/perl5/Weather/Com/Simple.pm is in libweather-com-perl 0.5.3-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
package Weather::Com::Simple;

use Carp;
use Weather::Com::Base qw(celsius2fahrenheit convert_winddirection);
use Weather::Com::Cached;

our $VERSION = sprintf "%d.%03d", q$Revision: 1.3 $ =~ /(\d+)/g;

#------------------------------------------------------------------------
# Constructor
#------------------------------------------------------------------------
sub new {
	my $proto = shift;
	my $class = ref($proto) || $proto;
	my $self  = {};
	my %parameters;

	# some general attributes
	$self->{PROXY} = "none";
	$self->{DEBUG} = 0;
	$self->{CACHE} = ".";

	# parameters provided by new method
	if ( ref( $_[0] ) eq "HASH" ) {
		%parameters = %{ $_[0] };
	} else {
		%parameters = @_;
	}

	$self = bless( $self, $class );

	# check mandatory parameters
	unless ( $parameters{place} ) {
		$self->_debug("ERROR: Location not specified");
		return undef;
	}

	# put wanted parameters into $self
	$self->{PLACE}      = $parameters{place};
	$self->{PROXY}      = $parameters{proxy} if ( $parameters{proxy} );
	$self->{PROXY_USER} = $parameters{proxy_user}
	  if ( $parameters{proxy_user} );
	$self->{PROXY_PASS} = $parameters{proxy_pass}
	  if ( $parameters{proxy_pass} );
	$self->{DEBUG} = $parameters{debug} if ( $parameters{debug} );
	$self->{CACHE} = $parameters{cache} if ( $parameters{cache} );

	# Weather::Com::Cached object
	my %weatherargs = (
						'current'    => 1,
						'forecast'   => 0,
						'proxy'      => $self->{PROXY},
						'proxy_user' => $self->{PROXY_USER},
						'proxy_pass' => $self->{PROXY_PASS},
						'debug'      => $self->{DEBUG},
						'cache'      => $self->{CACHE},
	);

	$weatherargs{timeout} = $parameters{timeout} if ( $parameters{timeout} );
	$weatherargs{partner_id} = $parameters{partner_id}
	  if ( $parameters{partner_id} );
	$weatherargs{license} = $parameters{license} if ( $parameters{license} );

	# initialize weather object
	$self->{WEATHER} = Weather::Com::Cached->new(%weatherargs);

	return $self;
}    # end new()

#------------------------------------------------------------------------
# accessor methods
#------------------------------------------------------------------------
sub get_weather {
	my $self = shift;
	my $allweather;
	my $place_result = $self->{WEATHER}->search( $self->{PLACE} );

	# check if search succeeded
	unless ($place_result) {
		$self->_debug($@);
		return undef;
	}

	foreach ( keys %{$place_result} ) {
		my $weatherdata = $self->{WEATHER}->get_weather($_);

		unless ($weatherdata) {
			$self->_debug($@);
			return 0;
		}

		my $place_weather = {

			# header data
			'place'   => $weatherdata->{loc}->{dnam},
			'updated' => _parse_timestring( $weatherdata->{cc}->{lsup} ),

			# temperature celsius/fahrenheit
			'celsius'             => $weatherdata->{cc}->{tmp},
			'temperature_celsius' => $weatherdata->{cc}->{tmp},
			'windchill_celsius'   => $weatherdata->{cc}->{flik},
			'fahrenheit' => celsius2fahrenheit( $weatherdata->{cc}->{tmp} ),
			'temperature_fahrenheit' =>
			  celsius2fahrenheit( $weatherdata->{cc}->{tmp} ),
			'windchill_fahrenheit' =>
			  celsius2fahrenheit( $weatherdata->{cc}->{flik} ),    

			# wind
			'wind'          => _parse_wind( $weatherdata->{cc}->{wind} ),
			'windspeed_kmh' =>
			  _parse_windspeed_kmh( $weatherdata->{cc}->{wind} ),
			'windspeed_mph' =>
			  _parse_windspeed_mph( $weatherdata->{cc}->{wind} ),

			# other
			'humidity'   => $weatherdata->{cc}->{hmid},
			'conditions' => $weatherdata->{cc}->{t},
			'pressure'   => _parse_pressure( $weatherdata->{cc}->{bar} ),
		};

		push( @{$allweather}, $place_weather );
	}

	return $allweather;
}

sub getweather {
	return get_weather(@_);
}

#------------------------------------------------------------------------
# internal parsing utilities
#------------------------------------------------------------------------
sub _parse_wind {
	my $winddata = shift;
	my $wind;

	if ( lc( $winddata->{s} ) =~ /calm/ ) {
		$wind = "calm";
	} else {
		my $kmh       = _parse_windspeed_kmh($winddata);
		my $mph       = _parse_windspeed_mph($winddata);
		my $direction = convert_winddirection( $winddata->{t} );
		$wind = "$mph mph $kmh km/h from the $direction";
	}
	return $wind;
}

sub _parse_windspeed_kmh {
	my $winddata = shift;
	my $speed;

	if ( lc( $winddata->{s} ) =~ /calm/ ) {
		$speed = "calm";
	} else {
		$speed = $winddata->{s};
	}
	return $speed;
}

sub _parse_windspeed_mph {
	my $winddata = shift;
	my $speed;

	if ( lc( $winddata->{s} ) =~ /calm/ ) {
		$speed = "calm";
	} else {
		$speed = sprintf( "%d", $winddata->{s} * 0.6213722 );
	}
	return $speed;
}

sub _parse_pressure {
	my $pressuredata = shift;
	my $pressure;

	my $hPa = $pressuredata->{r};
	$hPa =~ s/,//g;
	my $in = $hPa * 0.02953;

	$pressure = sprintf( "%.2f in / %.1f hPa", $in, $hPa );
}

sub _parse_timestring {
	my $timestring = shift;
	my @months = (
				   "",       "January",   "February", "March",
				   "April",  "May",       "June",     "July",
				   "August", "September", "October",  "November",
				   "Dezember"
	);

	my ( $date, $time, $ampm, $zone ) = split( / /, $timestring );
	my ( $month, $mday, $year ) = split( "/", $date );

	return "$time $ampm $zone on $months[$month] $mday, " . ( $year + 2000 );
}

#------------------------------------------------------------------------
# other internals
#------------------------------------------------------------------------
sub _debug {
	my $self   = shift;
	my $notice = shift;
	if ( $self->{DEBUG} ) {
		carp ref($self) . " DEBUG NOTE: $notice\n";
		return 1;
	}
	return 0;
}

1;

__END__

=pod

=head1 NAME

Weather::Com::Simple - Simple Wrapper around the L<Weather::Com::Cached> API

=head1 SYNOPSIS

  use Data::Dumper;
  use Weather::Com::Simple;
  
  # define parameters for weather search
  my %params = (
		'partner_id' => 'somepartnerid',
		'license'    => '12345678',
		'place'      => 'Heidelberg',
  );
  
  # instantiate a new weather.com object
  my $simple_weather = Weather::Com::Simple->new(%params);

  my $weather = $simple_weather->get_weather();
  
  print Dumper($weather);
  

=head1 DESCRIPTION

I<Weather::Com::Simple> is a very high level wrapper around I<Weather::Com::Cached>.
You provide a place to search for (e.g. a city or "city, country") and you'll get
back a simple hash containing some usefull weather information about all locations
whose name matches to the search string.

=head1 CONSTRUCTOR

=head2 new(hash or hashref)

The constructor takes the same hash or hashref as L<Weather::Com::Cached> does.
Please refer to that documentation for further details.

Except from the L<Weather::Com::Cached> parameters this constructor takes a
parameter I<place> which defines the location to search for. It is not
possible to provide the location to search to the I<get_weather()> method!

=head1 METHODS

=head2 get_weather()

This method invokes the L<Weather::Com::Cached> API to fetch some
weather information and returns an arrayref containing one
or many hashrefs with some high level weather information.

If no location matching the search string is found, it returns
I<undef>.

When you construct a L<Weather::Com::Simple> object like shown in
the synopsis above, the arrayref returned has the following structure:

  $VAR1 = [
		{
			'place'      => 'Heidelberg, Germany',
			'celsius'                => '0',
			'fahrenheit'             => '32',
			'temperature_celsius'    => '0',
			'temperature_fahrenheit' => '32'
			'windchill_celsius'      => '-6',
			'windchill_fahrenheit'   => '21',
			'windspeed_kmh'          => '26',
			'windspeed_mph'          => '16',
			'wind'       => '16 mph 26 km/h from the North Northeast',
			'updated'    => '11:50 AM Local on January 26, 2005',
			'conditions' => 'Partly Cloudy',
			'pressure'   => '30.21 in / 1023.0 hPa',
			'humidity'   => '60',
   		},
		{
			'place' => 'Heidelberg, KY',
			
			...
			
		},
		{
			'place' => 'Heidelberg, MS',
			
			...
			
		}
	];


=head1 SEE ALSO

See also documentation of L<Weather::Com> and L<Weather::Com::Cached>.

=head1 AUTHOR

Thomas Schnuecker, E<lt>thomas@schnuecker.deE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2004-2007 by Thomas Schnuecker

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

The data provided by I<weather.com> and made accessible by this OO
interface can be used for free under special terms. 
Please have a look at the application programming guide of
I<weather.com> (http://www.weather.com/services/xmloap.html)

=cut