blib/lib/Pinto/Locator/Stratopan.pm

filter: Statementstmt 59.5% 28 / 47 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 72.7% 8 / 11 Podpod 0.0% 0 / 2 totaltotal 46.7% 36 / 77 CC 7 SCAR 31.7
CC
7
Cov
45%
_locate_any
56.0
locate_package
2.0
locate_distribution
2.0
CRAP 23.8
« blib/lib/Pinto/Role/Installer.pm ↑ Summary blib/lib/App/Pinto/Command/list.pm »
1 # ABSTRACT: Locate targets using Stratopan services
2  
3 package Pinto::Locator::Stratopan;
4  
5 59 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 59 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 59 ▶use MooseX::MarkAsMethods ( autoclean => 1 );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 59 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 59 ▶use JSON qw(decode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 59 ▶use HTTP::Request::Common qw(GET);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 59 ▶use Pinto::Util qw(whine);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 59 ▶use Pinto::Constants qw(:stratopan);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #-----------------------------------------------------------------------------
17  
18 59 our $VERSION = '0.14'; # VERSION
19  
20 #-----------------------------------------------------------------------------
21  
22 59 extends qw(Pinto::Locator);
23  
24 #-----------------------------------------------------------------------------
25  
26 0 ▶sub locate_package {
Subroutine locate_package: not called CC=1 SCAR=6.9
Pod undocumented
27 0 my ($self, %args) = @_;
28  
29 0 return $self->_locate_any(%args);
30 }
31  
32 #-----------------------------------------------------------------------------
33  
34 0 ▶sub locate_distribution {
Subroutine locate_distribution: not called CC=1 SCAR=6.9
Pod undocumented
35 0 my ($self, %args) = @_;
36  
37 0 return $self->_locate_any(%args);
38 }
39  
40 #-----------------------------------------------------------------------------
41  
42 0 ▶sub _locate_any {
Subroutine _locate_any: not called CC=7 SCAR=40.3
43 0 my ($self, %args) = @_;
44  
45 0 my $uri = $PINTO_STRATOPAN_LOCATOR_URI->clone;
46 0 $uri->query_form(q => $args{target}->to_string);
47 0 my $response = $self->request(GET($uri));
48  
49 0 ▶ if (!$response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
50 0 my $status = $response->status_line;
51 0 whine "Stratopan is not responding: $status";
52 0 return;
53 }
54  
55 0 my $structs = eval { decode_json($response->content) };
56 0 ▶ whine "Invalid response from Stratopan: $@" and return if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
Condition0%0/5
$@ && (whine("Invalid response from Stratopan: $@") && (return))
!ll&&!rl&&r
000
whine("Invalid response from Stratopan: $@") and return
!ll
00
MC/DC0%0/2
$@ && (whine("Invalid response from Stratopan: $@") && (return))
$@ whine("Invalid response from Stratopan: $@")
Truth table0%0/3
A && B
A= $@B= whine("Invalid response from Stratopan: $@")
ABresult
0X0
100
111
57  
58 0 ▶ return unless my $latest = $structs->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless my $latest = $structs->[0] 0 0 0
59  
60 # Avoid autovivification here...
61 $latest->{version} = version->parse($latest->{version})
62 0 ▶ if exists $latest->{version};
Branch: 1 branch
BranchTrueFalseTotal
if exists $latest->{"version"} 0 0 0
63  
64 # Avoid autovivification here...
65 $latest->{uri} = URI->new($latest->{uri})
66 0 ▶ if exists $latest->{uri};
Branch: 1 branch
BranchTrueFalseTotal
if exists $latest->{"uri"} 0 0 0
67  
68 0 return $latest;
69 }
70  
71 #-----------------------------------------------------------------------------
72  
73 59 __PACKAGE__->meta->make_immutable;
74  
75 #-----------------------------------------------------------------------------
76 59 1;
77  
78 __END__
« blib/lib/Pinto/Role/Installer.pm ↑ Summary blib/lib/App/Pinto/Command/list.pm »