| 1 | package Weather::Com::Base; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use XML::Simple; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Time::Local; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use base qw(Weather::Com::Object Exporter); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | #-------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # Define some globals | ||||||||||||||||||||||||||||||||||||||||||
| 17 | #-------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||
| 19 | celsius2fahrenheit | ||||||||||||||||||||||||||||||||||||||||||
| 20 | fahrenheit2celsius | ||||||||||||||||||||||||||||||||||||||||||
| 21 | convert_winddirection | ||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 5 | our $VERSION = sprintf "%d.%03d", q$Revision: 1.9 $ =~ /(\d+)/g; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | my $CITY_SEARCH_URI = "http://xoap.weather.com/search/search?where="; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 5 | my $WEATHER_SEARCH_URI = "http://xoap.weather.com/weather/local/"; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 5 | my %winddir = ( | |||||||||||||||||||||||||||||||||||||||||
| 30 | "none" => "none", | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 'N/A' => "Not Available", | ||||||||||||||||||||||||||||||||||||||||||
| 32 | "VAR" => "Variable", | ||||||||||||||||||||||||||||||||||||||||||
| 33 | "N" => "North", | ||||||||||||||||||||||||||||||||||||||||||
| 34 | "NNW" => "North Northwest", | ||||||||||||||||||||||||||||||||||||||||||
| 35 | "NW" => "Northwest", | ||||||||||||||||||||||||||||||||||||||||||
| 36 | "WNW" => "West Northwest", | ||||||||||||||||||||||||||||||||||||||||||
| 37 | "W" => "West", | ||||||||||||||||||||||||||||||||||||||||||
| 38 | "WSW" => "West Southwest", | ||||||||||||||||||||||||||||||||||||||||||
| 39 | "SW" => "Southwest", | ||||||||||||||||||||||||||||||||||||||||||
| 40 | "SSW" => "South Southwest", | ||||||||||||||||||||||||||||||||||||||||||
| 41 | "S" => "South", | ||||||||||||||||||||||||||||||||||||||||||
| 42 | "SSE" => "South Southeast", | ||||||||||||||||||||||||||||||||||||||||||
| 43 | "SE" => "Southeast", | ||||||||||||||||||||||||||||||||||||||||||
| 44 | "ESE" => "East Southeast", | ||||||||||||||||||||||||||||||||||||||||||
| 45 | "E" => "East", | ||||||||||||||||||||||||||||||||||||||||||
| 46 | "ENE" => "East Northeast", | ||||||||||||||||||||||||||||||||||||||||||
| 47 | "NE" => "Northeast", | ||||||||||||||||||||||||||||||||||||||||||
| 48 | "NNE" => "North Northeast", | ||||||||||||||||||||||||||||||||||||||||||
| 49 | "Not Available" => 'N/A', | ||||||||||||||||||||||||||||||||||||||||||
| 50 | "North" => "N", | ||||||||||||||||||||||||||||||||||||||||||
| 51 | "North Northwest" => "NNW", | ||||||||||||||||||||||||||||||||||||||||||
| 52 | "Northwest" => "NW", | ||||||||||||||||||||||||||||||||||||||||||
| 53 | "West Northwest" => "WNW", | ||||||||||||||||||||||||||||||||||||||||||
| 54 | "West" => "W", | ||||||||||||||||||||||||||||||||||||||||||
| 55 | "West Southwest" => "WSW", | ||||||||||||||||||||||||||||||||||||||||||
| 56 | "Southwest" => "SW", | ||||||||||||||||||||||||||||||||||||||||||
| 57 | "South Southwest" => "SSW", | ||||||||||||||||||||||||||||||||||||||||||
| 58 | "South" => "S", | ||||||||||||||||||||||||||||||||||||||||||
| 59 | "South Southeast" => "SSE", | ||||||||||||||||||||||||||||||||||||||||||
| 60 | "Southeast" => "SE", | ||||||||||||||||||||||||||||||||||||||||||
| 61 | "East Southeast" => "ESE", | ||||||||||||||||||||||||||||||||||||||||||
| 62 | "East" => "E", | ||||||||||||||||||||||||||||||||||||||||||
| 63 | "East Northeast" => "ENE", | ||||||||||||||||||||||||||||||||||||||||||
| 64 | "Northeast" => "NE", | ||||||||||||||||||||||||||||||||||||||||||
| 65 | "North Northeast" => "NNE", | ||||||||||||||||||||||||||||||||||||||||||
| 66 | "Variable" => "VAR", | ||||||||||||||||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 70 | # Constructor | ||||||||||||||||||||||||||||||||||||||||||
| 71 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 3 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 3 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 3 | my %parameters; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | # parameters provided by new method | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 3 | ▶ | if ( ref( $_[0] ) eq "HASH" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | %parameters = %{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | %parameters = @_; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | # get SUPER instance | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | my $self = $class->SUPER::new( \%parameters ); | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | # some general attributes | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 3 | $self->{PROXY} = "none"; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 3 | $self->{TIMEOUT} = 180; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | $self->{DEBUG} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | # license information | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 3 | $self->{PARTNER_ID} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | $self->{LICENSE_KEY} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | # API specific attributes | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 3 | $self->{UNITS} = 'm'; # could be 'm' for metric or 's' for us standard | |||||||||||||||||||||||||||||||||||||||||
| 98 | 3 | $self->{CC} = 0; # show current conditions true/false | |||||||||||||||||||||||||||||||||||||||||
| 99 | 3 | $self->{FORECAST} = 0; # multi day forecast 0 = no, 1..10 days | |||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | $self->{LINKS} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | # save params for further use | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 3 | $self->{ARGS} = \%parameters; | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | # do some initialization with validity checking | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | $self = $self->_init(); | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | # and some debugging output | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | $self->_debug( "Returning object: " . Dumper($self) ); | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 3 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=21 SCAR=47.9
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 3 | my $params = $self->{ARGS}; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | # set proxy if param is set properly | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 3 | ▶ | if ( $params->{proxy} && ( lc( $params->{proxy} ) ne "none" ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$params->{"proxy"} and lc $params->{"proxy"} ne "none"
MC/DC0%0/2
$params->{"proxy"} and lc $params->{"proxy"} ne "none"
$params->{"proxy"}
lc $params->{"proxy"} ne "none"
Truth table33%1/3
A and B
A= $params->{"proxy"}B= lc $params->{"proxy"} ne "none"
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | unless ( $params->{proxy} =~ /^(http|HTTP)\:\/\// ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | die ref($self) | |||||||||||||||||||||||||||||||||||||||||
| 122 | . ": 'proxy' parameter has to start with 'http://'!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $self->{PROXY} = $params->{proxy}; | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | # set proxy authentication data if param is set properly | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 3 | ▶ | if ( $params->{proxy_user} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$params->{"proxy_user"} and $params->{"proxy_pass"} and lc $params->{"proxy_user"} ne "none"
$params->{"proxy_user"} and $params->{"proxy_pass"}
MC/DC0%0/3
$params->{"proxy_user"} and $params->{"proxy_pass"} and lc $params->{"proxy_user"} ne "none"
$params->{"proxy_user"}
$params->{"proxy_pass"}
lc $params->{"proxy_user"} ne "none"
Truth table25%1/4
A and B and C
A= $params->{"proxy_user"}B= $params->{"proxy_pass"}C= lc $params->{"proxy_user"} ne "none"
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | && $params->{proxy_pass} | ||||||||||||||||||||||||||||||||||||||||||
| 130 | && ( lc( $params->{proxy_user} ) ne "none" ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 131 | { | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $self->{PROXY_USER} = $params->{proxy_user}; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $self->{PROXY_PASS} = $params->{proxy_pass}; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | # set timeout if it is a possitive integer or 0 | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 3 | ▶ | if ( $params->{timeout} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | unless ( ( $params->{timeout} =~ /^\d+$/ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$params->{"timeout"} =~ /^\d+$/ and $params->{"timeout"} > -1
MC/DC0%0/2
$params->{"timeout"} =~ /^\d+$/ and $params->{"timeout"} > -1
$params->{"timeout"} =~ /^\d+$/
$params->{"timeout"} > -1
Truth table0%0/3
A and B
A= $params->{"timeout"} =~ /^\d+$/B= $params->{"timeout"} > -1
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | && ( $params->{timeout} > -1 ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 140 | { | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | die ref($self) | |||||||||||||||||||||||||||||||||||||||||
| 142 | . ": 'timeout' parameter has to be a positive integer or 0!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $self->{TIMEOUT} = $params->{timeout}; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | # set units of measure if set to 'm' or 's' | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 3 | ▶ | if ( $params->{units} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | unless ( lc( $params->{units} ) =~ /^m|s$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | die ref($self) | |||||||||||||||||||||||||||||||||||||||||
| 151 | . ": 'units' parameter has to be set to 'm' or 's'!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | $self->{UNITS} = $params->{units} if ( $params->{units} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | # forecast has to be between 0 and 10 | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 3 | ▶ | if ( $params->{forecast} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | unless ( $params->{forecast} =~ /^[1]?\d$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | die ref($self) | |||||||||||||||||||||||||||||||||||||||||
| 161 | . ": 'forecast' parameter has to between 0 and 10!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $self->{FORECAST} = $params->{forecast}; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | # set params that don't need to be checked | ||||||||||||||||||||||||||||||||||||||||||
| 167 | $self->{PARTNER_ID} = $params->{partner_id} | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 3 | ▶ | if ( $params->{partner_id} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 3 | ▶ | $self->{LICENSE_KEY} = $params->{license} if ( $params->{license} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 3 | ▶ | $self->{DEBUG} = $params->{debug} if ( $params->{debug} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 3 | ▶ | $self->{CC} = $params->{current} if ( $params->{current} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 3 | ▶ | $self->{LINKS} = $params->{links} if ( $params->{links} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 3 | ▶ | if ( $params->{lang} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $self->{LANGUAGE} = $params->{lang}; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 3 | $self->{LANGUAGE} = 'en_US'; | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 184 | # getting data from weather.com | ||||||||||||||||||||||||||||||||||||||||||
| 185 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub search { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
search: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my $place = shift; | |||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | # set error and die if no place provided | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | unless ($place) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | die ref($self), ": ERROR Please provide a location to search for!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | # build up HTTP GET request | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | $place = uri_escape($place); | |||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my $searchlocation = $CITY_SEARCH_URI . $place; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $searchlocation .= '&prod=xoap'; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | if ( $self->{PARTNER_ID} && $self->{LICENSE_KEY} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"PARTNER_ID"} and $self->{"LICENSE_KEY"}
MC/DC0%0/2
$self->{"PARTNER_ID"} and $self->{"LICENSE_KEY"}
$self->{"PARTNER_ID"}
$self->{"LICENSE_KEY"}
Truth table0%0/3
A and B
A= $self->{"PARTNER_ID"}B= $self->{"LICENSE_KEY"}
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | $searchlocation .= '&par=' . $self->{PARTNER_ID}; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | $searchlocation .= '&key=' . $self->{LICENSE_KEY}; | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $self->_debug($searchlocation); | |||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | # get information | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my $locationXML; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | while ( !$locationXML || ( $locationXML !~ /^\<\?xml/ ) && ( $i < 3 ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $locationXML or not $locationXML =~ /^\<\?xml/ and $i < 3
not $locationXML =~ /^\<\?xml/ and $i < 3
MC/DC0%0/3
not $locationXML or not $locationXML =~ /^\<\?xml/ and $i < 3
not $locationXML
not $locationXML =~ /^\<\?xml/
$i < 3
Truth table0%0/4
not(A) or not(B) and C
A= not $locationXMLB= not $locationXML =~ /^\<\?xml/C= $i < 3
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | eval { $locationXML = $self->_getWebPage($searchlocation); }; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | die ref($self), | |||||||||||||||||||||||||||||||||||||||||
| 213 | ": ERROR No response from weather server while searching place: $@\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | # check if at least one location has been returned | ||||||||||||||||||||||||||||||||||||||||||
| 217 | # if not return 0 | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | if ( $locationXML =~ /^\s*$/g ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | $self->_debug( | |||||||||||||||||||||||||||||||||||||||||
| 220 | "No location found using $place (url escaped) as search string." ); | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | return 0 unless ( $locationXML =~ /^\<\?xml/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | # parse answer | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my $simpleHash = XMLin($locationXML); | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | # XML::Simple behaves differently when one location is return than | ||||||||||||||||||||||||||||||||||||||||||
| 233 | # when more locations are returned ... | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | my $locations = undef; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if ( $simpleHash->{loc}->{content} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | $locations->{ $simpleHash->{loc}->{id} } = | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $simpleHash->{loc}->{content}; | |||||||||||||||||||||||||||||||||||||||||
| 238 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | foreach ( keys %{ $simpleHash->{loc} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $locations->{$_} = $simpleHash->{loc}->{$_}->{content}; | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $self->_debug( Dumper($locations) ); | |||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | return $locations; | |||||||||||||||||||||||||||||||||||||||||
| 247 | } # end search() | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | sub get_weather { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_weather: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my $locid = shift; | |||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | unless ($locid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | die ref($self), ": ERROR Please provide a location id!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | # prepare HTTP Request | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | my $searchlocation = $WEATHER_SEARCH_URI . $locid; | |||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $searchlocation .= '?unit=' . $self->{UNITS}; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $searchlocation .= '&prod=xoap'; | |||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | if ( $self->{PARTNER_ID} && $self->{LICENSE_KEY} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"PARTNER_ID"} and $self->{"LICENSE_KEY"}
MC/DC0%0/2
$self->{"PARTNER_ID"} and $self->{"LICENSE_KEY"}
$self->{"PARTNER_ID"}
$self->{"LICENSE_KEY"}
Truth table0%0/3
A and B
A= $self->{"PARTNER_ID"}B= $self->{"LICENSE_KEY"}
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $searchlocation .= '&par=' . $self->{PARTNER_ID}; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | $searchlocation .= '&key=' . $self->{LICENSE_KEY}; | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | if ( $self->{CC} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $searchlocation .= '&cc=*'; | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | if ( $self->{FORECAST} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | $searchlocation .= '&dayf=' . $self->{FORECAST}; | |||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if ( $self->{LINKS} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | $searchlocation .= '&link=xoap'; | |||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | # get weather data | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $self->_debug($searchlocation); | |||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | my $weatherXML; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | eval { $weatherXML = $self->_getWebPage($searchlocation); }; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | die ref($self), | |||||||||||||||||||||||||||||||||||||||||
| 282 | ": ERROR No response from weather server while loading data: $@\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | # parse weather data | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my %options = ( | |||||||||||||||||||||||||||||||||||||||||
| 287 | ForceArray => ["day"], | ||||||||||||||||||||||||||||||||||||||||||
| 288 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my $simpleHash = XMLin($weatherXML, %options); | |||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | # do some error handling if weather.com returns an error message | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | if ( $simpleHash->{err} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | die ref($self), ": ERROR ", $simpleHash->{err}->{content}, "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | $self->_debug(Dumper($simpleHash)); | |||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | return $simpleHash; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | #-------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 302 | # Utility function to get one web pages content or die on error | ||||||||||||||||||||||||||||||||||||||||||
| 303 | #-------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | sub _getWebPage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getWebPage: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | my $path = shift; | |||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | # instantiate a new user agent, with proxy if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my $ua = LWP::UserAgent->new(); | |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | my $request = HTTP::Request->new( "GET" => $path ); | |||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | $ua->proxy( 'http', $self->{PROXY} ) | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | if ( lc( $self->{PROXY} ) ne "none" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | $request->proxy_authorization_basic( $self->{PROXY_USER}, | ||||||||||||||||||||||||||||||||||||||||||
| 315 | $self->{PROXY_PASS} ) | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | if ( lc( $self->{PROXY_USER} ) ne "none" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | $ua->timeout( $self->{TIMEOUT} ); | |||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | # print some debugging info on the user agent object | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | $self->_debug("This is the user agent we wanna use:"); | |||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | $self->_debug( Dumper($ua) ); | |||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $self->_debug("Together with this request:"); | |||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $self->_debug( Dumper($request) ); | |||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | # get the html page | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | my $response = $ua->request($request); | |||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | # and do some error handling | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $html = undef; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | if ( $response->is_success() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $html = $response->content(); | |||||||||||||||||||||||||||||||||||||||||
| 332 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | die "ERROR While getting resource: $path :\n", $response->status_line(), | |||||||||||||||||||||||||||||||||||||||||
| 334 | "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | # and print the complete HTML response for debugging purposes | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | $self->_debug($html); | |||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | return $html; | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 344 | # other internals | ||||||||||||||||||||||||||||||||||||||||||
| 345 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 346 | 3 | ▶ | sub _debug { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_debug: called CC=2 SCAR=7.9
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 3 | my $notice = shift; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 3 | ▶ | if ( $self->{DEBUG} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | carp ref($self) . " DEBUG NOTE: $notice\n"; | |||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | ######################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 357 | # | ||||||||||||||||||||||||||||||||||||||||||
| 358 | # STATIC methods go here | ||||||||||||||||||||||||||||||||||||||||||
| 359 | # | ||||||||||||||||||||||||||||||||||||||||||
| 360 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 361 | # methods for temperature conversion | ||||||||||||||||||||||||||||||||||||||||||
| 362 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 1 | ▶ | sub celsius2fahrenheit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
celsius2fahrenheit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 1 | my $celsius = shift; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 1 | my $fahrenheit = sprintf( "%d", ( $celsius * 1.8 ) + 32 ); | |||||||||||||||||||||||||||||||||||||||||
| 366 | 1 | return $fahrenheit; | |||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 1 | ▶ | sub fahrenheit2celsius { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fahrenheit2celsius: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 1 | my $fahrenheit = shift; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 1 | my $celsius = sprintf( "%d", ( $fahrenheit - 32 ) / 1.8 ); | |||||||||||||||||||||||||||||||||||||||||
| 372 | 1 | return $celsius; | |||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 376 | # internal time conversion methods | ||||||||||||||||||||||||||||||||||||||||||
| 377 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | sub _lsup2epoc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lsup2epoc: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | # this method returns epoc for gmt corresponding to | ||||||||||||||||||||||||||||||||||||||||||
| 381 | # the provided last update value (lsup) | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | my $lsup = shift; | |||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | my $gmt_offset = shift; | |||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | my ( $date, $time, $ampm, $zone ) = split( / /, $lsup ); | |||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | my ( $mon, $mday, $year ) = split( "/", $date ); | |||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | my ( $hour, $min ) = split( /:/, $time ); | |||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | $year += 100; | |||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | $hour += 12 if ( $ampm eq "PM" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | my $gmtime = timegm( 0, $min, $hour, $mday, $mon - 1, $year ); | |||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $gmtime -= $gmt_offset * 3600; | |||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | return $gmtime; | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | sub _epoc2lsup { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_epoc2lsup: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | # this method takes epoc (gmt) and builds up the weather.com | ||||||||||||||||||||||||||||||||||||||||||
| 401 | # internally used last update format (lsup) | ||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | my $epoc = shift; | |||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | my $gmt_offset = shift; | |||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | my ( $sec, $min, $hour, $mday, $mon, $year ) = | |||||||||||||||||||||||||||||||||||||||||
| 406 | gmtime( $epoc + $gmt_offset * 3600 ); | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $year -= 100; | |||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | $year = '0' . $year if ( $year < 10 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | $mon++; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | my $ampm = "AM"; | |||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | if ( $hour > 12 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | $hour -= 12; | |||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | $ampm = "PM"; | |||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | my $time = join( ":", $hour, $min ); | |||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | my $date = join( "/", $mon, $mday, $year ); | |||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | my $lsup = join( " ", $date, $time, $ampm, "Local Time" ); | |||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | return $lsup; | |||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | sub _simple2twentyfour { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_simple2twentyfour: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | my $stime = shift; | |||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | my $colon = index( $stime, ":" ); | |||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | my $hour = substr( $stime, 0, $colon ); | |||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | my $minutes = substr( $stime, $colon + 1, 2 ); | |||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | my $ampm = substr( $stime, 6 ); | |||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | if ( lc($ampm) =~ /PM/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | return $hour + 12 . ":" . $minutes; | |||||||||||||||||||||||||||||||||||||||||
| 434 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | return "$hour:$minutes"; | |||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 440 | # wind direction conversion methods | ||||||||||||||||||||||||||||||||||||||||||
| 441 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 442 | 5 | ▶ | sub convert_winddirection { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
convert_winddirection: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 5 | my $indir = shift; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 5 | return $winddir{$indir}; | |||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 448 | __END__ | ||||||||||||||||||||||||||||||||||||||||||