| 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)
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 14 | my $base = 'Weather-OpenWeatherMap'; | |||||||||||||||||||||||||||
| 27 | 14 | my $path; | |||||||||||||||||||||||||||
| 28 | DTYPE: { | ||||||||||||||||||||||||||||
| 29 | 14 | ▶ | if ($type eq 'current') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$type =~ /^3day/ or $type eq "forecast"
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"
| |||||||||||||||||||||||||||||
| 35 | 3 | $path = dist_file($base, '3day.json'); | |||||||||||||||||||||||||||
| 36 | last DTYPE | ||||||||||||||||||||||||||||
| 37 | 3 | } | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 9 | ▶ | if ($type eq 'hourly') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$type eq "failure" or $type eq "error"
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"
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$type eq "find" or $type eq "search"
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"
| |||||||||||||||||||||||||||||
| 50 | 1 | $path = dist_file($base, 'find.json'); | |||||||||||||||||||||||||||
| 51 | last DTYPE | ||||||||||||||||||||||||||||
| 52 | 1 | } | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 14 | ▶ | if ($path) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 73 | 4 | ▶ | if ($url =~ /forecast/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||