| 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')
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')
| |||||||||||||||||||||||||||||||||||||||
| 25 | 20 | my $base = 'Weather-OpenWeatherMap'; | |||||||||||||||||||||||||||||||||||||
| 26 | 20 | ▶ | my $path = dist_file( $base, | ||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||