OpenWeatherMap/Test.pm

filter: Statementstmt 95.0% 57 / 60 Branchbran 88.8% 16 / 18 Conditioncond 63.6% 7 / 11 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 2 totaltotal 85.4% 94 / 110 CC 14 SCAR 18.1
CC
14
Cov
90%
get_test_data
11.5
request
4.0
requested_count
2.0
CRAP 6.1
« OpenWeatherMap.pm ↑ Summary OpenWeatherMap/Result/Forecast.pm »
1 package Weather::OpenWeatherMap::Test;
2 3 $Weather::OpenWeatherMap::Test::VERSION = '0.003001';
3 =pod
4  
5 =for Pod::Coverage .*
6  
7 =cut
8  
9 3 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use File::ShareDir 'dist_dir', 'dist_file';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 ▶use parent 'Exporter::Tiny';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 our @EXPORT = our @EXPORT_OK = qw/
18 get_test_data
19 mock_http_ua
20 /;
21  
22  
23 sub get_test_data {
24 14 ▶ my $type = lc (shift || return);
Subroutine get_test_data: called CC=11 SCAR=24.4
Pod undocumented
Condition50%1/2
shift() || (return)
l!l
140
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
25  
26 14 my $base = 'Weather-OpenWeatherMap';
27 14 my $path;
28 DTYPE: {
29 14 ▶ if ($type eq 'current') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "current") 2 12 14
30 2 $path = dist_file($base, 'current.json');
31 last DTYPE
32 2 }
33  
34 12 ▶ if ($type =~ /^3day/ || $type eq 'forecast') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^3day/ or $type eq "forecast") 3 9 12
Condition100%3/3
$type =~ /^3day/ or $type eq "forecast"
l!l&&r!l&&!r
129
MC/DC100%2/2
$type =~ /^3day/ or $type eq "forecast"
$type =~ /^3day/ $type eq "forecast"
Truth table100%3/3
A or B
A= $type =~ /^3day/B= $type eq "forecast"
ABresult
1X1
011
000
35 3 $path = dist_file($base, '3day.json');
36 last DTYPE
37 3 }
38  
39 9 ▶ if ($type eq 'hourly') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "hourly") 2 7 9
40 2 $path = dist_file($base, 'hourly.json');
41 last DTYPE
42 2 }
43  
44 7 ▶ if ($type eq 'failure' || $type eq 'error') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "failure" or $type eq "error") 6 1 7
Condition66%2/3
$type eq "failure" or $type eq "error"
l!l&&r!l&&!r
601
MC/DC50%1/2
$type eq "failure" or $type eq "error"
$type eq "failure" $type eq "error"
Truth table66%2/3
A or B
A= $type eq "failure"B= $type eq "error"
ABresult
1X1
011
000
45 6 $path = dist_file($base, 'failure.json');
46 last DTYPE
47 6 }
48  
49 1 ▶ if ($type eq 'find' || $type eq 'search') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "find" or $type eq "search") 1 0 1
Condition33%1/3
$type eq "find" or $type eq "search"
l!l&&r!l&&!r
100
MC/DC0%0/2
$type eq "find" or $type eq "search"
$type eq "find" $type eq "search"
Truth table33%1/3
A or B
A= $type eq "find"B= $type eq "search"
ABresult
1X1
011
000
50 1 $path = dist_file($base, 'find.json');
51 last DTYPE
52 1 }
53 }
54  
55 14 ▶ if ($path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path) 14 0 14
56 14 return path($path)->slurp_utf8
57 }
58  
59 0 confess "Unknown type $type"
60 }
61  
62 { package
63 Weather::OpenWeatherMap::Test::MockUA;
64 3 ▶ use strict; use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
65 3 require HTTP::Response;
66 3 ▶ use parent 'LWP::UserAgent';
Subroutine BEGIN: called CC=1 SCAR=0.0
67 0 ▶ sub requested_count { my ($self) = @_; $self->{'__requested'} }
Subroutine requested_count: not called CC=1 SCAR=6.9
68 sub request {
69 4 ▶ my ($self, $http_request) = @_;
Subroutine request: called CC=4 SCAR=13.9
70 4 my $url = $http_request->uri;
71 $self->{'__requested'} ?
72 4 ▶ ++$self->{'__requested'} : ($self->{'__requested'} = 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{'__requested'} ? : 2 2 4
73 4 ▶ if ($url =~ /forecast/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ /forecast/) 2 2 4
74 return $url =~ /daily/ ?
75 HTTP::Response->new( 200 => undef => [] => $self->{forecast_json} )
76 : HTTP::Response->new( 200 => undef => [] => $self->{hourly_json} )
77 2 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
$url =~ /daily/ ? : 1 1 2
78 HTTP::Response->new( 200 => undef => [] => $self->{current_json} )
79 2 }
80 }
81  
82 3 sub mock_http_ua {
83 2 ▶ return bless +{
Subroutine mock_http_ua: called CC=1 SCAR=0.0
Pod undocumented
84 forecast_json => get_test_data('forecast'),
85 hourly_json => get_test_data('hourly'),
86 current_json => get_test_data('current'),
87 }, 'Weather::OpenWeatherMap::Test::MockUA'
88 }
89  
90 3 1;
« OpenWeatherMap.pm ↑ Summary OpenWeatherMap/Result/Forecast.pm »