/usr/share/perl5/Weather/Com/CurrentConditions.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 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | package Weather::Com::CurrentConditions;
use 5.006;
use strict;
use warnings;
use Weather::Com::AirPressure;
use Weather::Com::DateTime;
use Weather::Com::Moon;
use Weather::Com::UVIndex;
use Weather::Com::Wind;
use Weather::Com::L10N;
use base "Weather::Com::Cached";
our $VERSION = sprintf "%d.%03d", q$Revision: 1.14 $ =~ /(\d+)/g;
#------------------------------------------------------------------------
# Constructor
#------------------------------------------------------------------------
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my %parameters;
# parameters provided by new method
if ( ref( $_[0] ) eq "HASH" ) {
%parameters = %{ $_[0] };
} else {
%parameters = @_;
}
unless ( $parameters{location_id} ) {
die "You need to provide a location id!\n";
}
# set some parameters to sensible values for a
# current conditions object
$parameters{current} = 1;
$parameters{forecast} = 0;
$parameters{links} = 0;
# creating the SUPER instance
my $self = $class->SUPER::new( \%parameters );
$self->{ID} = $parameters{location_id};
# getting first weather information
$self->{BAR} = undef;
$self->{UV} = undef;
$self->{MOON} = undef;
$self->{WEATHER} = $self->get_weather( $self->{ID} );
$self->{WIND} = undef;
$self->{LAST_XML_UPDATE} = undef;
# remember instantiation time (and later last update time)
$self->{LSUP} = time();
return $self;
} # end new()
#------------------------------------------------------------------------
# refresh weather data
#------------------------------------------------------------------------
sub refresh {
my $self = shift;
my $now = time();
# only refresh if last update has been more than 15 min ago
if ( ( $now - $self->{LSUP} ) > 900 ) {
$self->{WEATHER} = $self->get_weather( $self->{ID} );
$self->{LSUP} = $now;
}
return 1;
}
#------------------------------------------------------------------------
# access location data
#------------------------------------------------------------------------
sub id {
my $self = shift;
return $self->{ID};
}
sub name {
my $self = shift;
$self->refresh();
return $self->{WEATHER}->{loc}->{dnam};
}
sub icon {
my $self = shift;
return $self->{WEATHER}->{cc}->{icon};
}
sub description {
my $self = shift;
my $language = shift;
$self->refresh();
return $self->get_language_handle($language)
->maketext( lc( $self->{WEATHER}->{cc}->{t} ) );
}
sub temperature {
my $self = shift;
$self->refresh();
return $self->{WEATHER}->{cc}->{tmp};
}
sub windchill {
my $self = shift;
$self->refresh();
return $self->{WEATHER}->{cc}->{flik};
}
sub humidity {
my $self = shift;
$self->refresh();
return $self->{WEATHER}->{cc}->{hmid};
}
sub pressure {
my $self = shift;
$self->refresh();
unless ( $self->{BAR} ) {
$self->{BAR} = Weather::Com::AirPressure->new( $self->{ARGS} );
}
$self->{BAR}->update( $self->{WEATHER}->{cc}->{bar} );
return $self->{BAR};
}
sub dewpoint {
my $self = shift;
$self->refresh();
return $self->{WEATHER}->{cc}->{dewp};
}
sub moon {
my $self = shift;
$self->refresh();
unless ( $self->{MOON} ) {
$self->{MOON} = Weather::Com::Moon->new( $self->{ARGS} );
}
$self->{MOON}->update( $self->{WEATHER}->{cc}->{moon} );
return $self->{MOON};
}
sub uv_index {
my $self = shift;
$self->refresh();
unless ( $self->{UV} ) {
$self->{UV} = Weather::Com::UVIndex->new( $self->{ARGS} );
}
$self->{UV}->update( $self->{WEATHER}->{cc}->{uv} );
return $self->{UV};
}
sub visibility {
my $self = shift;
$self->refresh();
return $self->{WEATHER}->{cc}->{vis};
}
sub wind {
my $self = shift;
$self->refresh();
unless ( $self->{WIND} ) {
$self->{WIND} = Weather::Com::Wind->new( $self->{ARGS} );
}
$self->{WIND}->update( $self->{WEATHER}->{cc}->{wind} );
return $self->{WIND};
}
sub observatory {
my $self = shift;
$self->refresh();
return $self->{WEATHER}->{cc}->{obst};
}
sub last_updated {
my $self = shift;
$self->refresh();
unless ( $self->{LAST_XML_UPDATE} ) {
$self->{LAST_XML_UPDATE} =
Weather::Com::DateTime->new( $self->{ARGS}->{zone} );
}
$self->{LAST_XML_UPDATE}->set_lsup( $self->{WEATHER}->{cc}->{lsup} );
return $self->{LAST_XML_UPDATE};
}
1;
__END__
=pod
=head1 NAME
Weather::Com::CurrentConditions - class containing current weather conditions
=head1 SYNOPSIS
#!/usr/bin/perl -w
use Weather::Com::Finder;
# you have to fill in your ids from weather.com here
my $PartnerId = 'somepartnerid';
my $LicenseKey = 'mylicense';
my %weatherargs = (
'partner_id' => $PartnerId,
'license' => $LicenseKey,
'language' => 'de',
);
my $finder = Weather::Com::Finder->new(%weatherargs);
# if you want an array of locations:
my @locations = $finder->find('Heidelberg');
my $conditions = $locations[0]->current_conditions();
print "Found weather for city: ", $location->name(), "\n";
print "Current conditions are ", $conditions->description(), "\n";
print "Current temperature is ", $conditions->temperature(), "°C\n";
print "... as found out by observatory ", $conditions->observatory(), "\n";
=head1 DESCRIPTION
Using I<Weather::Com::CurrentCondition> objects provide current weather
conditions of its parent object (a location) to you.
You get I<Weather::Com::CurrentConditions> objects by calling the method
C<current_conditions()> of your location object.
I<Weather::Com::CurrentConditions> is a subclass of I<Weather::Com::Cached>.
An instance of this class will update itself corresponding to the
caching rules any time one of its methods is called.
=head1 CONSTRUCTOR
=head2 new(hash or hashref)
The constructor will usually not be used directly because you get a ready
to use current conditions objects from your location object.
If you ever want to instantiate current conditions objects on your own, you have
to provide the same configuration hash or hashref to the constructor
you usually would provide to the C<new()> method of I<Weather::Com::Finder>.
In addition it is necessary to add a hash element C<location_id> to this
config hash. The C<location_id> has to be a valid I<weather.com>
location id.
=head1 METHODS
=head2 id()
Returns the location id used to instantiate this object.
=head2 name()
Returns the name of the location this current conditions belong to.
=head2 description([$language])
Returns a textual representation of the current weather conditions.
This description is translated if you specified the I<language> option
as argument for your I<Weather::Com::Finder>.
This attribute is I<dynamic language enabled>.
=head2 dewpoint()
Returns the dewpoint.
=head2 humidity()
Returns the humidity (in %).
=head2 icon()
Returns the number of the icon that can be used to display the
current weather conditions. These icons are available with the
I<weather.com> sdk. You can download this sdk from I<weather.com>
after you've registered to get your license.
=head2 last_updated()
Returns a I<Weather::Com::DateTime> object containing the date and
time of the last update as provided by I<weather.com>.
=head2 observatory()
Returns the name of the observatory that provided the current conditions
to I<weather.com>.
=head2 pressure()
Returns a I<Weather::Com::AirPressure> object.
Please refer to L<Weather::Com::AirPressure> for further
details.
=head2 temperature()
Returns the temperature (depending on how you instantiated your
I<Weather::Com::Finder> you'll get centigrade (default) or degrees
fahrenheit).
=head2 uv_index()
Returns a I<Weather::Com::UVIndex> object.
Please refer to L<Weather::Com::UVIndex> for further
details.
=head2 visibility()
Returns the visibility (depending on how you instantiated your
I<Weather::Com::Finder> you'll get km (default) or miles).
=head2 wind()
Returns a I<Weather::Com::Wind> object.
Please refer to L<Weather::Com::Wind> for further
details.
=head2 windchill()
Returns the windchill temperature (depending on how you instantiated your
I<Weather::Com::Finder> you'll get centigrade (default) or degrees
fahrenheit).
=head1 SEE ALSO
See also documentation of L<Weather::Com>, L<Weather::Com::CurrentConditions>,
L<Weather::Com::Units>.
=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
|