Agent.pm

filter: Statementstmt 81.2% 52 / 64 Branchbran 42.8% 6 / 14 Conditioncond 26.6% 4 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 77.7% 14 / 18 Podpod 100% 6 / 6 totaltotal 65.6% 82 / 125 CC 13 SCAR 16.2
CC
13
Cov
67%
download
13.0
_download_remote
6.0
is_local
3.8
CRAP 5.1
« Xml/Pom/Profile.pm ↑ Summary Repositories.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Maven::Agent;
5 2 $Maven::Agent::VERSION = '1.12';
6 # ABSTRACT: A base agent for working with maven
7 # PODNAME: Maven::Agent
8  
9 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Maven::Maven;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub new {
14 6 ▶ return bless( {}, shift )->_init(@_);
Subroutine new: called CC=1 SCAR=0.0
Pod documented
15 }
16  
17 sub download {
18 2 ▶ my ( $self, $artifact, %options ) = @_;
Subroutine download: called CC=8 SCAR=25.7
Pod documented
19  
20 2 ▶ if ( !ref($artifact)
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $artifact and $artifact->isa("Maven::Artifact") and $artifact->get_uri) 0 0 0
Condition33%2/6
ref $artifact and $artifact->isa("Maven::Artifact") and $artifact->get_uri
!ll&&!rl&&r
200
ref $artifact and $artifact->isa("Maven::Artifact")
!ll&&!rl&&r
200
MC/DC0%0/3
ref $artifact and $artifact->isa("Maven::Artifact") and $artifact->get_uri
ref $artifact $artifact->isa("Maven::Artifact") $artifact->get_uri
Truth table25%1/4
A and B and C
A= ref $artifactB= $artifact->isa("Maven::Artifact")C= $artifact->get_uri
ABCresult
0XX0
10X0
1100
1111
21 || !$artifact->isa('Maven::Artifact')
22 || !$artifact->get_uri() )
23 {
24 2 $artifact = $self->resolve_or_die($artifact);
25 }
26  
27 2 ▶ if ( $self->is_local($artifact) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_local($artifact)) 2 0 2
28 2 my $path = $artifact->get_uri()->path();
29 2 ▶ if ( $options{to} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"to"}) 2 0 2
30 2 my $file = _to_file( $options{to}, $artifact );
31 2 ▶ if ( $file ne $path ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file ne $path) 2 0 2
32 2 copy( $path, $file );
33 2 $path = $file;
34 }
35 }
36 2 return $path;
37 }
38  
39 return $self->_download_remote( $artifact, $options{to}
40 0 ▶ ? _to_file( $options{to}, $artifact )
Branch: 1 branch
BranchTrueFalseTotal
$options{'to'} ? : 0 0 0
41 : () );
42 }
43  
44 sub _default_agent {
45 6 ▶ my ( $self, @options ) = @_;
Subroutine _default_agent: called CC=1 SCAR=0.0
46 6 require LWP::UserAgent;
47 6 my $agent = LWP::UserAgent->new(@options);
48 6 $agent->env_proxy(); # because why not?
49 6 return $agent;
50 }
51  
52 sub _download_remote {
53 0 ▶ my ( $self, $artifact, $file ) = @_;
Subroutine _download_remote: not called CC=2 SCAR=17.9
54  
55 0 ▶ $file ||= Maven::Agent::DownloadedFile->new();
Condition0%0/3
$file ||= "Maven::Agent::DownloadedFile"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$file ||= "Maven::Agent::DownloadedFile"->new
$file "Maven::Agent::DownloadedFile"->new
Truth table0%0/3
A ||= B
A= $fileB= "Maven::Agent::DownloadedFile"->new
ABresult
1X1
011
000
56  
57 0 $self->{agent}->get( $artifact->get_uri(), ':content_file' => "$file" );
58  
59 0 return $file;
60 }
61  
62 sub get_maven {
63 6 ▶ return shift->{maven};
Subroutine get_maven: called CC=1 SCAR=0.0
Pod documented
64 }
65  
66 sub _init {
67 6 ▶ my ( $self, %options ) = @_;
Subroutine _init: called CC=2 SCAR=7.0
68  
69 $options{agent} = $self->_default_agent(%options)
70 6 ▶ unless ( $options{agent} );
Branch: 1 branch
BranchTrueFalseTotal
unless $options{"agent"} 6 0 6
71  
72 6 $self->{agent} = $options{agent};
73 6 $self->{maven} = Maven::Maven->new(%options);
74  
75 6 return $self;
76 }
77  
78 sub is_local {
79 2 ▶ my ( $self, $artifact ) = @_;
Subroutine is_local: called CC=3 SCAR=13.3
Pod documented
80 2 my $uri = $artifact->get_uri();
81 2 ▶ return ( $uri->scheme() =~ /^file$/i
Condition33%2/6
$uri->scheme =~ /^file$/i && ($uri->host eq '' || $uri->host =~ /^localhost$/)
!ll&&!rl&&r
002
$uri->host eq "" or $uri->host =~ /^localhost$/
l!l&&r!l&&!r
200
MC/DC0%0/3
$uri->scheme =~ /^file$/i && ($uri->host eq '' || $uri->host =~ /^localhost$/)
$uri->scheme =~ /^file$/i $uri->host eq "" $uri->host =~ /^localhost$/
Truth table25%1/4
A && B or C
A= $uri->scheme =~ /^file$/iB= $uri->host eq ""C= $uri->host =~ /^localhost$/
ABCresult
0XX0
1000
11X1
1011
82 && ( $uri->host() eq '' || $uri->host() =~ /^localhost$/ ) );
83 }
84  
85 sub resolve {
86 0 ▶ return shift->{maven}->get_repositories()->resolve(@_);
Subroutine resolve: not called CC=1 SCAR=6.9
Pod documented
87 }
88  
89 sub resolve_or_die {
90 3 ▶ return shift->{maven}->get_repositories()->resolve_or_die(@_);
Subroutine resolve_or_die: called CC=1 SCAR=0.0
Pod documented
91 }
92  
93 sub _to_file {
94 2 ▶ my ( $to, $artifact ) = @_;
Subroutine _to_file: called CC=2 SCAR=6.9
95 2 ▶ if ( -d $to ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $to) 1 1 2
96 1 $to = File::Spec->catfile( $to, "$artifact->{artifactId}." . $artifact->get_packaging() );
97 }
98 2 return $to;
99 }
100  
101 package Maven::Agent::DownloadedFile;
102 2 $Maven::Agent::DownloadedFile::VERSION = '1.12';
103 # Wraps a temp file to hold a reference so as to keep the destructor from
104 # getting called. It will provide the filename when used as a string.
105  
106 2 ▶use overload q{""} => 'filename', fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
107  
108 sub new {
109 0 ▶ my $self = bless( {}, shift );
Subroutine new: not called CC=1 SCAR=6.9
110 0 my $file = File::Temp->new();
111  
112 0 $self->{handle} = $file;
113 0 $self->{name} = $file->filename();
114  
115 0 return $self;
116 }
117  
118 sub filename {
119 0 ▶ return $_[0]->{name};
Subroutine filename: not called CC=1 SCAR=6.9
120 }
121  
122 2 1;
123  
124 __END__
« Xml/Pom/Profile.pm ↑ Summary Repositories.pm »