OpenWeatherMap/Test.pm

filter: Statementstmt 78.5% 33 / 42 Branchbran 55.0% 11 / 20 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 9 / 12 Podpod 0.0% 0 / 2 totaltotal 66.6% 54 / 81 CC 12 SCAR 20.4
CC
12
Cov
69%
get_test_data
12.8
request
12.0
requested_count
2.0
CRAP 7.7
↑ Summary OpenWeatherMap/Cache.pm »
1 package Weather::OpenWeatherMap::Test;
2 3 $Weather::OpenWeatherMap::Test::VERSION = '0.005001';
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 20 ▶ my $type = lc shift || confess "No type specified";
Subroutine get_test_data: called CC=10 SCAR=25.5
Pod undocumented
Condition33%1/3
lc shift() || confess('No type specified')
l!l&&r!l&&!r
2000
MC/DC0%0/2
lc shift() || confess('No type specified')
lc shift() confess('No type specified')
Truth table33%1/3
A || B
A= lc shift()B= confess('No type specified')
ABresult
1X1
011
000
25 20 my $base = 'Weather-OpenWeatherMap';
26 20 ▶ my $path = dist_file( $base,
Branch: 8 branches
BranchTrueFalseTotal
$type eq 'current' ? : 2 18 20
$type =~ /^3day/ ? : 3 15 18
$type eq 'forecast' ? : 0 15 15
$type eq 'hourly' ? : 2 13 15
$type eq 'failure' ? : 10 3 13
$type eq 'error' ? : 0 3 3
$type eq 'find' ? : 3 0 3
$type eq 'search' ? : 0 0 0
27 $type eq 'current' ? 'current.json'
28 : $type =~ /^3day/ ? '3day.json'
29 : $type eq 'forecast' ? '3day.json'
30 : $type eq 'hourly' ? 'hourly.json'
31 : $type eq 'failure' ? 'failure.json'
32 : $type eq 'error' ? 'failure.json'
33 : $type eq 'find' ? 'find.json'
34 : $type eq 'search' ? 'find.json'
35 : confess "Unknown type $type"
36 );
37 20 path($path)->slurp_utf8
38 }
39  
40 { package
41 Weather::OpenWeatherMap::Test::MockUA;
42 3 ▶ use strict; use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
43 3 require HTTP::Response;
44 3 ▶ use parent 'LWP::UserAgent';
Subroutine BEGIN: called CC=1 SCAR=0.0
45 0 ▶ sub requested_count { my ($self) = @_; $self->{'__requested'} }
Subroutine requested_count: not called CC=1 SCAR=6.9
46 sub request {
47 0 ▶ my ($self, $http_request) = @_;
Subroutine request: not called CC=3 SCAR=24.8
48 0 my $url = $http_request->uri;
49 0 $self->{'__requested'}++;
50 0 ▶ if ($url =~ /forecast/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ /forecast/) 0 0 0
51 return $url =~ /daily/ ?
52 HTTP::Response->new( 200 => undef => [] => $self->{forecast_json} )
53 : HTTP::Response->new( 200 => undef => [] => $self->{hourly_json} )
54 0 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
$url =~ /daily/ ? : 0 0 0
55 HTTP::Response->new( 200 => undef => [] => $self->{current_json} )
56 0 }
57 }
58  
59 3 sub mock_http_ua {
60 0 ▶ return bless +{
Subroutine mock_http_ua: not called CC=1 SCAR=6.9
Pod undocumented
61 forecast_json => get_test_data('forecast'),
62 hourly_json => get_test_data('hourly'),
63 current_json => get_test_data('current'),
64 }, 'Weather::OpenWeatherMap::Test::MockUA'
65 }
66  
67 3 1;
↑ Summary OpenWeatherMap/Cache.pm »