| 1 | package Weather::Com::Wind; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use 5.006; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use Weather::Com::L10N; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | ▶ | use Weather::Com::Base qw/convert_winddirection/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 2 | ▶ | use base 'Weather::Com::Object'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | our $VERSION = sprintf "%d.%03d", q$Revision: 1.10 $ =~ /(\d+)/g; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | #------------------------------------------------------------------------ | ||||||||||||||||||||
| 13 | # Constructor | ||||||||||||||||||||
| 14 | #------------------------------------------------------------------------ | ||||||||||||||||||||
| 15 | 2 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||
| 16 | 2 | my $proto = shift; | |||||||||||||||||||
| 17 | 2 | ▶ | 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
| |||||||||||||||||||||
| 18 | 2 | my %parameters; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | # parameters provided by new method | ||||||||||||||||||||
| 21 | 2 | ▶ | if ( ref( $_[0] ) eq "HASH" ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 22 | 0 | %parameters = %{ $_[0] }; | |||||||||||||||||||
| 23 | } else { | ||||||||||||||||||||
| 24 | 2 | %parameters = @_; | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 2 | my $self = $class->SUPER::new( \%parameters ); | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | # getting first weather information | ||||||||||||||||||||
| 30 | 2 | $self->{SPEED} = -1; | |||||||||||||||||||
| 31 | 2 | $self->{GUST} = -1; | |||||||||||||||||||
| 32 | 2 | $self->{DIR_DEGREES} = -1; | |||||||||||||||||||
| 33 | 2 | $self->{DIR_TXT} = 'N/A'; | |||||||||||||||||||
| 34 | 2 | return $self; | |||||||||||||||||||
| 35 | } # end new() | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | #------------------------------------------------------------------------ | ||||||||||||||||||||
| 38 | # update wind data | ||||||||||||||||||||
| 39 | #------------------------------------------------------------------------ | ||||||||||||||||||||
| 40 | 3 | ▶ | sub update { | ||||||||||||||||||
|
Subroutine
update: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||
| 41 | 3 | my $self = shift; | |||||||||||||||||||
| 42 | 3 | my %wind; | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 3 | ▶ | if ( ref( $_[0] ) eq "HASH" ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 0 | %wind = %{ $_[0] }; | |||||||||||||||||||
| 46 | } else { | ||||||||||||||||||||
| 47 | 3 | %wind = @_; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | # handle non existent wind data | ||||||||||||||||||||
| 51 | 3 | ▶ | unless ( $wind{s} ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 52 | 1 | $self->{SPEED} = -1; | |||||||||||||||||||
| 53 | 1 | $self->{GUST} = -1; | |||||||||||||||||||
| 54 | 1 | $self->{DIR_DEGREES} = -1; | |||||||||||||||||||
| 55 | 1 | $self->{DIR_TXT} = 'N/A'; | |||||||||||||||||||
| 56 | } elsif ( lc( $wind{s} ) eq "calm" ) { | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | # special rules apply if speed is non-numeric | ||||||||||||||||||||
| 59 | 1 | $self->{SPEED} = 0; | |||||||||||||||||||
| 60 | 1 | $self->{GUST} = 0; | |||||||||||||||||||
| 61 | 1 | $self->{DIR_DEGREES} = -1; | |||||||||||||||||||
| 62 | 1 | $self->{DIR_TXT} = 'N/A'; | |||||||||||||||||||
| 63 | } else { | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | # else update object data | ||||||||||||||||||||
| 66 | 1 | $self->{SPEED} = $wind{s}; | |||||||||||||||||||
| 67 | 1 | $self->{GUST} = $wind{gust}; | |||||||||||||||||||
| 68 | 1 | $self->{DIR_DEGREES} = $wind{d}; | |||||||||||||||||||
| 69 | 1 | $self->{DIR_TXT} = $wind{t}; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | #------------------------------------------------------------------------ | ||||||||||||||||||||
| 75 | # accessor methods | ||||||||||||||||||||
| 76 | #------------------------------------------------------------------------ | ||||||||||||||||||||
| 77 | 4 | ▶ | sub speed { | ||||||||||||||||||
|
Subroutine
speed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 78 | 4 | my $self = shift; | |||||||||||||||||||
| 79 | 4 | return $self->{SPEED}; | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 4 | ▶ | sub maximum_gust { | ||||||||||||||||||
|
Subroutine
maximum_gust: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 83 | 4 | my $self = shift; | |||||||||||||||||||
| 84 | 4 | return $self->{GUST}; | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 4 | ▶ | sub direction_degrees { | ||||||||||||||||||
|
Subroutine
direction_degrees: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 88 | 4 | my $self = shift; | |||||||||||||||||||
| 89 | 4 | return $self->{DIR_DEGREES}; | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 5 | ▶ | sub direction_short { | ||||||||||||||||||
|
Subroutine
direction_short: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 93 | 5 | my $self = shift; | |||||||||||||||||||
| 94 | 5 | my $language = shift; | |||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 5 | return $self->get_language_handle($language)->maketext( $self->{DIR_TXT} ); | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 5 | ▶ | sub direction_long { | ||||||||||||||||||
|
Subroutine
direction_long: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 100 | 5 | my $self = shift; | |||||||||||||||||||
| 101 | 5 | my $language = shift; | |||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 5 | my $dir = convert_winddirection( $self->{DIR_TXT} ); | |||||||||||||||||||
| 104 | 5 | return $self->get_language_handle($language)->maketext($dir); | |||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 2 | 1; | |||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | __END__ | ||||||||||||||||||||