lib/Module/Provision/TraitFor/CPANDistributions.pm

filter: Statementstmt 28.4% 46 / 162 Branchbran 2.7% 1 / 36 Conditioncond 0.0% 0 / 38 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 48.0% 12 / 25 Podpod 100% 4 / 4 totaltotal 21.9% 63 / 287 CC 40 SCAR 32.9
CC
40
Cov
20%
__ANON__
90.0
__ANON__
42.0
__ANON__
30.0
CRAP 26.7
« lib/Module/Provision/TraitFor/AddingFiles.pm ↑ Summary lib/Module/Provision/TraitFor/CreatingDistributions.pm »
1 package Module::Provision::TraitFor::CPANDistributions;
2  
3 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Class::Usul::Constants qw( EXCEPTION_CLASS FALSE NUL OK TRUE );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Class::Usul::Crypt::Util qw( decrypt_from_config encrypt_for_config
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 is_encrypted );
8 1 ▶use Class::Usul::Functions qw( ensure_class_loaded throw );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Class::Usul::Types qw( NonEmptySimpleStr );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use HTTP::Request::Common qw( POST );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use HTTP::Status;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Unexpected::Functions qw( PathNotFound Unspecified );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 requires qw( add_leader config debug distname dist_version dumper
18 info loc log next_argv output run_cmd yorn );
19  
20 # Private attributes
21 has '_debug_http_method' => is => 'ro', isa => NonEmptySimpleStr,
22 1 ▶ builder => sub { $ENV{CPAN_DELETE_FILES_DISPLAY_HTTP_BODY}
Subroutine _build__debug_http_method: called CC=2 SCAR=7.2
23 1 ▶ ? 'as_string' : 'headers_as_string' };
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'CPAN_DELETE_FILES_DISPLAY_HTTP_BODY'} ? : 0 1 1
24  
25 # Private methods
26 0 ▶my $_convert_versions_to_paths = sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
27 0 ▶ my ($self, $versions, $args) = @_; my $paths = []; $args //= {};
Condition0%0/2
$args //= {}
l!l
00
MC/DC0%0/1
$args //= {}
$args
Truth table0%0/2
A
A= $args
Aresult
11
00
28  
29 0 my $distname = $self->distname;
30 0 ▶ my $subdir = $args->{subdir} ? $args->{subdir}.'/' : NUL;
Branch: 1 branch
BranchTrueFalseTotal
$args->{'subdir'} ? : 0 0 0
31  
32 0 ▶ for my $version (@{ $versions // [] }) {
Condition0%0/2
$versions // []
l!l
00
MC/DC0%0/1
$versions // []
$versions
Truth table0%0/2
A
A= $versions
Aresult
11
00
33 0 for my $extn (qw(meta readme tar.gz)) {
34 0 push @{ $paths }, "${subdir}${distname}-${version}.${extn}";
35 }
36 }
37  
38 0 return $paths;
39 1 };
40  
41 0 ▶my $_dist_path = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
42 0 my ($self, $ver) = @_; my $file;
43  
44 0 ▶ if ($ver) { $file = $self->distname."-${ver}.tar.gz" }
Branch: 1 branch
BranchTrueFalseTotal
if ($ver) { } 0 0 0
45 else {
46 0 $file = $self->distname.'-'.$self->dist_version.'.tar.gz';
47 0 ▶ -f $file or $file = $self->distname.'-v'.$self->dist_version.'.tar.gz';
Branch: 1 branch
BranchTrueFalseTotal
-f $file or $file = $self->distname . '-v' . $self->dist_version . '.tar.gz' 0 0 0
48 }
49  
50 0 ▶ -f $file or throw PathNotFound, [ $file ];
Branch: 1 branch
BranchTrueFalseTotal
-f $file or &throw(PathNotFound(), [$file]) 0 0 0
51  
52 0 return $file
53 1 };
54  
55 0 ▶my $_log_http_debug = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
56 0 ▶ my ($self, $type, $obj, $msg) = @_; $self->debug or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->debug or return 0 0 0
57  
58 0 my $method = $self->_debug_http_method;
59  
60 0 ▶ $self->log->debug( $_ ) for ( $msg ? $msg : (),
Branch: 1 branch
BranchTrueFalseTotal
$msg ? : 0 0 0
61 "----- ${type} BEGIN -----\n",
62 $obj->$method()."\n",
63 "----- ${type} END -------\n" );
64 0 return;
65 1 };
66  
67 0 ▶my $_read_rc_file = sub {
Subroutine __ANON__: not called CC=9 SCAR=45.0
68 0 my $self = shift; my $conf = $self->config; my $attr = {};
69  
70 0 for ($conf->my_home->catfile( '.pause' )->chomp->getlines) {
71 0 ▶ ($_ and $_ !~ m{ \A \s* \# }mx) or next;
Branch: 1 branch
BranchTrueFalseTotal
$_ and not $_ =~ / \A \s* \# /mx or next 0 0 0
Condition0%0/3
$_ and not $_ =~ / \A \s* \# /mx
!ll&&!rl&&r
000
MC/DC0%0/2
$_ and not $_ =~ / \A \s* \# /mx
$_ not $_ =~ / \A \s* \# /mx
Truth table0%0/3
A and not(B)
A= $_B= not $_ =~ / \A \s* \# /mx
ABresult
0X0
100
111
72  
73 0 my ($k, $v) = m{ \A \s* (\w+) (?: \s+ (.+))? \z }mx;
74  
75 0 ▶ exists $attr->{ $k } and throw 'Multiple entries for [_1]', [ $k ];
Branch: 1 branch
BranchTrueFalseTotal
exists $attr->{$k} and &throw("Multiple entries for [_1]", [$k]) 0 0 0
76 0 ▶ $attr->{ $k } = $v // NUL;
Condition0%0/2
$v // ""
l!l
00
MC/DC0%0/1
$v // ""
$v
Truth table0%0/2
A
A= $v
Aresult
11
00
77 }
78  
79 0 my $pword; exists $attr->{password}
80 and $pword = $attr->{password}
81 and is_encrypted $pword
82 0 ▶ and $attr->{password} = decrypt_from_config $conf, $pword;
Branch: 1 branch
BranchTrueFalseTotal
exists $attr->{"password"} and $pword = $attr->{"password"} and &is_encrypted($pword) and $attr->{"password"} = &decrypt_from_config($conf, $pword) 0 0 0
Condition0%0/6
exists $attr->{"password"} and $pword = $attr->{"password"} and &is_encrypted($pword)
!ll&&!rl&&r
000
exists $attr->{"password"} and $pword = $attr->{"password"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $attr->{"password"} and $pword = $attr->{"password"} and &is_encrypted($pword)
exists $attr->{"password"} $pword = $attr->{"password"} &is_encrypted($pword)
Truth table0%0/4
A and B and C
A= exists $attr->{"password"}B= $pword = $attr->{"password"}C= &is_encrypted($pword)
ABCresult
0XX0
10X0
1100
1111
83  
84 0 return $attr;
85 1 };
86  
87 0 ▶my $_ua_string = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
88 0 my $self = shift;
89 0 ▶ my $class = blessed $self || $self;
Condition0%0/3
builtin::blessed($self) || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($self) || $self
builtin::blessed($self) $self
Truth table0%0/3
A || B
A= builtin::blessed($self)B= $self
ABresult
1X1
011
000
90 0 ▶ my $ver = $class->VERSION // 'dev';
Condition0%0/2
$class->VERSION // "dev"
l!l
00
MC/DC0%0/1
$class->VERSION // "dev"
$class->VERSION
Truth table0%0/2
A
A= $class->VERSION
Aresult
11
00
91  
92 0 return "${class}/${ver}";
93 1 };
94  
95 0 ▶my $_write_rc_file = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
96 0 my ($self, $attr) = @_; my $conf = $self->config;
97  
98 0 my $file = $conf->my_home->catfile( '.pause' );
99  
100 0 $attr->{password} = encrypt_for_config $conf, $attr->{password};
101  
102 0 $file->println( "${_} ".$attr->{ $_ } ) for (sort keys %{ $attr });
103  
104 0 return;
105 1 };
106  
107 0 ▶my $_get_delete_request = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
108 0 my ($self, $files, $args, $uri) = @_;
109  
110 my @body = ( HIDDENNAME => $args->{user},
111 0 SUBMIT_pause99_delete_files_delete => 'Delete', );
112  
113 0 for my $file (@{ $files }) {
114 0 push @body, 'pause99_delete_files_FILE', $file;
115 }
116  
117 0 my $request = POST( $uri, \@body );
118  
119 0 $request->authorization_basic( $args->{user}, $args->{password} );
120 0 $self->$_log_http_debug( 'REQUEST', $request );
121 0 return $request;
122 1 };
123  
124 0 ▶my $_throw_on_error = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
125 0 my ($self, $uri, $target, $response) = @_;
126  
127 0 ▶ defined $response
Branch: 1 branch
BranchTrueFalseTotal
defined $response or &throw("Request completely failed - we got undef back: [_1]", [$Module::Provision::TraitFor::CPANDistributions::OS_ERROR]) 0 0 0
128 or throw 'Request completely failed - we got undef back: [_1]',
129 [ $OS_ERROR ];
130  
131 0 ▶ if ($response->is_error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_error) 0 0 0
132 0 ▶ my $class = blessed $self || $self;
Condition0%0/3
builtin::blessed($self) || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($self) || $self
builtin::blessed($self) $self
Truth table0%0/3
A || B
A= builtin::blessed($self)B= $self
ABresult
1X1
011
000
133  
134 0 ▶ $response->code == RC_NOT_FOUND and throw
Branch: 1 branch
BranchTrueFalseTotal
$response->code == 404 and &throw("PAUSE's CGI for handling messages seems to have moved!\n(HTTP response code of 404 from the [_1] web server)\nIt used to be: [_2]\nPlease inform the maintainer of [_3]\n", [$target, $uri, $class]) 0 0 0
135 "PAUSE's CGI for handling messages seems to have moved!\n".
136 "(HTTP response code of 404 from the [_1] web server)\n".
137 "It used to be: [_2]\nPlease inform the maintainer of [_3]\n",
138 [ $target, $uri, $class ];
139  
140 0 throw "Request failed error code [_1]\n Message: [_2]\n",
141 [ $response->code, $response->message ];
142 }
143  
144 0 $self->$_log_http_debug( 'RESPONSE', $response, 'Looks OK!' );
145 0 $self->info( '[_1] delete request sent ok [[_2]]',
146 { args => [ $target, $response->code ] } );
147 0 return;
148 1 };
149  
150 0 ▶my $_delete_files = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
151 0 ▶ my ($self, $files, $args) = @_; my $target = $args->{target} || 'PAUSE';
Condition0%0/2
$args->{'target'} || 'PAUSE'
l!l
00
MC/DC0%0/1
$args->{'target'} || 'PAUSE'
$args->{'target'}
Truth table0%0/2
A
A= $args->{'target'}
Aresult
11
00
152  
153 0 $self->info( 'Registering to delete files with the [_1] web server',
154 { args => [ $target ] } );
155  
156 0 ensure_class_loaded( 'LWP::UserAgent' );
157  
158 0 my $agent = LWP::UserAgent->new;
159  
160 0 $agent->agent( $self->$_ua_string ); $agent->env_proxy;
161 0 ▶ $args->{http_proxy} and $agent->proxy( http => $args->{http_proxy} );
Branch: 1 branch
BranchTrueFalseTotal
$args->{"http_proxy"} and $agent->proxy("http", $args->{"http_proxy"}) 0 0 0
162  
163 0 ▶ my $uri = $args->{delete_files_uri} // $self->config->delete_files_uri;
Condition0%0/3
$args->{"delete_files_uri"} // $self->config->delete_files_uri
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{"delete_files_uri"} // $self->config->delete_files_uri
$args->{"delete_files_uri"} $self->config->delete_files_uri
Truth table0%0/3
A // B
A= $args->{"delete_files_uri"}B= $self->config->delete_files_uri
ABresult
1X1
011
000
164 0 my $request = $self->$_get_delete_request( $files, $args, $uri );
165  
166 0 $self->info( 'POSTing delete files request to [_1]', { args => [ $uri ] } );
167 0 $self->$_throw_on_error( $uri, $target, $agent->request( $request ) );
168 0 return;
169 1 };
170  
171 # Public methods
172 0 ▶sub cpan_upload : method {
Subroutine cpan_upload: not called CC=4 SCAR=30.0
Pod documented
173 0 ▶ my ($self, $ver) = @_; $ver //= $self->next_argv;
Condition0%0/3
$ver //= $self->next_argv
l!l&&r!l&&!r
000
MC/DC0%0/2
$ver //= $self->next_argv
$ver $self->next_argv
Truth table0%0/3
A //= B
A= $verB= $self->next_argv
ABresult
1X1
011
000
174  
175 0 my $file = $self->$_dist_path( $ver );
176 0 ▶ my $args = $self->$_read_rc_file; $args->{subdir} //= lc $self->distname;
Condition0%0/2
$args->{"subdir"} //= lc $self->distname
l!l
00
MC/DC0%0/1
$args->{"subdir"} //= lc $self->distname
$args->{"subdir"}
Truth table0%0/2
A
A= $args->{"subdir"}
Aresult
11
00
177 0 my $prompt = $self->add_leader( $self->loc( 'Really upload to CPAN' ) );
178  
179 exists $args->{dry_run}
180 0 ▶ or $args->{dry_run} = not $self->yorn( $prompt, FALSE, TRUE, 0 );
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{"dry_run"} or $args->{"dry_run"} = !$self->yorn($prompt, 0, 1, 0) 0 0 0
181  
182 0 ensure_class_loaded( 'CPAN::Uploader' );
183  
184 0 CPAN::Uploader->upload_file( $file, $args );
185 0 return OK;
186 }
187  
188 0 ▶sub delete_cpan_files : method {
Subroutine delete_cpan_files: not called CC=4 SCAR=30.0
Pod documented
189 0 my $self = shift;
190 0 ▶ my $args = $self->$_read_rc_file; $args->{subdir} //= lc $self->distname;
Condition0%0/2
$args->{"subdir"} //= lc $self->distname
l!l
00
MC/DC0%0/1
$args->{"subdir"} //= lc $self->distname
$args->{"subdir"}
Truth table0%0/2
A
A= $args->{"subdir"}
Aresult
11
00
191 0 my $files = $self->$_convert_versions_to_paths( $self->extra_argv, $args );
192 0 my $prompt = $self->loc( 'Really delete files from CPAN' );
193 0 $prompt = $self->add_leader( $prompt );
194  
195 exists $args->{dry_run}
196 0 ▶ or $args->{dry_run} = not $self->yorn( $prompt, FALSE, TRUE, 0 );
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{"dry_run"} or $args->{"dry_run"} = !$self->yorn($prompt, 0, 1, 0) 0 0 0
197  
198 0 ▶ if ($args->{dry_run}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'dry_run'}) { } 0 0 0
199 0 $self->output( 'By request, cowardly refusing to do anything at all' );
200 0 $self->output( "The following would have been used to delete files:\n" );
201 0 $self->dumper( $args );
202 0 $self->dumper( $files );
203 }
204 0 else { $self->$_delete_files( $files, $args ) }
205  
206 0 return OK;
207 }
208  
209 0 ▶sub set_cpan_password : method {
Subroutine set_cpan_password: not called CC=2 SCAR=17.9
Pod documented
210 0 my $self = shift; my $args = $self->$_read_rc_file;
211  
212 0 ▶ $args->{password} = $self->next_argv or throw Unspecified, [ 'password' ];
Branch: 1 branch
BranchTrueFalseTotal
$args->{"password"} = $self->next_argv or &throw(Unspecified(), ["password"]) 0 0 0
213 0 $self->$_write_rc_file( $args );
214 0 return OK;
215 }
216  
217 0 ▶sub test_upload : method {
Subroutine test_upload: not called CC=2 SCAR=17.9
Pod documented
218 0 ▶ my ($self, $ver) = @_; $ver //= $self->next_argv;
Condition0%0/3
$ver //= $self->next_argv
l!l&&r!l&&!r
000
MC/DC0%0/2
$ver //= $self->next_argv
$ver $self->next_argv
Truth table0%0/3
A //= B
A= $verB= $self->next_argv
ABresult
1X1
011
000
219  
220 0 my $conf = $self->config;
221 0 my $id = $conf->remote_test_id;
222 0 my $script = $conf->remote_script;
223 0 my $file = $self->$_dist_path( $ver );
224 0 my $args = { in => 'stdin', out => 'stdout', };
225  
226 0 $self->run_cmd( [ 'scp', $file, "${id}:/tmp" ] );
227 0 $self->run_cmd( [ 'ssh', '-t', $id, "${script} ${file}" ], $args );
228  
229 0 return OK;
230 }
231  
232 1 1;
233  
234 __END__
« lib/Module/Provision/TraitFor/AddingFiles.pm ↑ Summary lib/Module/Provision/TraitFor/CreatingDistributions.pm »