Com/Finder.pm

filter: Statementstmt 60.5% 43 / 71 Branchbran 36.6% 11 / 30 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 8 / 10 Podpod 100% 2 / 2 totaltotal 55.0% 65 / 118 CC 18 SCAR 27.1
CC
18
Cov
53%
find
30.0
new
18.2
_debug
6.0
CRAP 15.0
« Com/DayForecast.pm ↑ Summary Com/Forecast.pm »
1 package Weather::Com::Finder;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Weather::Com::Cached;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Weather::Com::Location;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = sprintf "%d.%03d", q$Revision: 1.8 $ =~ /(\d+)/g;
12  
13 #------------------------------------------------------------------------
14 # Constructor
15 #------------------------------------------------------------------------
16 1 ▶sub new {
Subroutine new: called CC=13 SCAR=29.0
Pod documented
17 1 my $proto = shift;
18 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
19 1 my $self = {};
20 1 my %parameters = ();
21  
22 # parameters provided by new method
23 1 ▶ if ( ref( $_[0] ) eq "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 1 1
24 0 %parameters = %{ $_[0] };
25 } else {
26 1 %parameters = @_;
27 }
28  
29 # god, bless the object
30 1 $self = bless( $self, $class );
31  
32 # Weather::Com::Cached object for searching
33 1 my %weatherargs = ();
34
35 # define proxy args
36 1 ▶ $weatherargs{proxy} = $parameters{proxy} if ( $parameters{proxy} );
Branch: 1 branch
BranchTrueFalseTotal
if $parameters{"proxy"} 0 1 1
37 $weatherargs{proxy_user} = $parameters{proxy_user}
38 1 ▶ if ( $parameters{proxy_user} );
Branch: 1 branch
BranchTrueFalseTotal
if $parameters{"proxy_user"} 0 1 1
39 $weatherargs{proxy_pass} = $parameters{proxy_pass}
40 1 ▶ if ( $parameters{proxy_pass} );
Branch: 1 branch
BranchTrueFalseTotal
if $parameters{"proxy_pass"} 0 1 1
41
42 # other weather arguments...
43 1 ▶ $weatherargs{units} = $parameters{units} if ( $parameters{units} );
Branch: 1 branch
BranchTrueFalseTotal
if $parameters{"units"} 0 1 1
44 1 ▶ $weatherargs{debug} = $parameters{debug} if ( $parameters{debug} );
Branch: 1 branch
BranchTrueFalseTotal
if $parameters{"debug"} 0 1 1
45 1 ▶ $weatherargs{cache} = $parameters{cache} if ( $parameters{cache} );
Branch: 1 branch
BranchTrueFalseTotal
if $parameters{"cache"} 0 1 1
46 1 ▶ $weatherargs{timeout} = $parameters{timeout} if ( $parameters{timeout} );
Branch: 1 branch
BranchTrueFalseTotal
if $parameters{"timeout"} 0 1 1
47 $weatherargs{partner_id} = $parameters{partner_id}
48 1 ▶ if ( $parameters{partner_id} );
Branch: 1 branch
BranchTrueFalseTotal
if $parameters{"partner_id"} 0 1 1
49 1 ▶ $weatherargs{license} = $parameters{license} if ( $parameters{license} );
Branch: 1 branch
BranchTrueFalseTotal
if $parameters{"license"} 0 1 1
50 1 ▶ $weatherargs{language} = $parameters{language} if ( $parameters{language} );
Branch: 1 branch
BranchTrueFalseTotal
if $parameters{"language"} 1 0 1
51  
52 # initialize weather object
53 1 $self->{ARGS} = \%weatherargs;
54 1 $self->{WEATHER} = Weather::Com::Cached->new(%weatherargs);
55  
56 1 return $self;
57 } # end new()
58  
59 #------------------------------------------------------------------------
60 # find weather
61 #------------------------------------------------------------------------
62 0 ▶sub find {
Subroutine find: not called CC=5 SCAR=34.0
Pod documented
63 0 my $self = shift;
64 0 my $locString = shift;
65  
66 # search locations
67 0 my $loc_weather = $self->{WEATHER}->search($locString);
68 0 ▶ unless ($loc_weather) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($loc_weather) 0 0 0
69 0 $self->_debug("No location found using '$locString' for search!");
70 0 return 0;
71 }
72  
73 # create a Weather::Com::Location for each location found
74 0 my @locations = ();
75 0 foreach ( keys %{$loc_weather} ) {
76 0 my %weatherargs = %{ $self->{ARGS} };
77 0 $weatherargs{location_id} = $_;
78 0 $weatherargs{location_name} = $loc_weather->{$_};
79
80 0 my $location = Weather::Com::Location->new(%weatherargs);
81 0 push( @locations, $location );
82 }
83  
84 0 $self->_debug("Location Objects: " . Dumper(\@locations));
85  
86 # return an array if called in list context or a scalar
87 # if called in void or scalar context
88
89 0 ▶ unless(@locations) {
Branch: 2 branches
BranchTrueFalseTotal
if (@locations) { } 0 0 0
if (do { wantarray }) { } 0 0 0
90 0 return undef;
91 } elsif ( wantarray() ) {
92 0 return @locations;
93 } else {
94 0 return \@locations;
95 }
96 }
97  
98 #------------------------------------------------------------------------
99 # other internals
100 #------------------------------------------------------------------------
101 0 ▶sub _debug {
Subroutine _debug: not called CC=2 SCAR=17.9
102 0 my $self = shift;
103 0 my $notice = shift;
104 0 ▶ if ( $self->{ARGS}->{debug} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ARGS"}{"debug"}) 0 0 0
105 0 carp ref($self) . " DEBUG NOTE: $notice\n";
106 0 return 1;
107 }
108 0 return 0;
109 }
110  
111 1 1;
112  
113 __END__
« Com/DayForecast.pm ↑ Summary Com/Forecast.pm »