CPAN/Maker/Bootstrapper/Role/PAUSEUpload.pm

filter: Statementstmt 61.9% 39 / 63 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 92.3% 12 / 13 Podpod 0.0% 0 / 1 totaltotal 48.1% 51 / 106 CC 11 SCAR 41.5
CC
11
Cov
45%
cmd_publish_to_cpan
132.0
BEGIN
1.0
BEGIN
1.0
CRAP 63.7
« CPAN/Maker/Bootstrapper/Role/DepsFilter.pm ↑ Summary Text/ASCIITable/FixANSI.pm »
1 package CPAN::Maker::Bootstrapper::Role::PAUSEUpload;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use CLI::Simple::Constants qw(:booleans);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use CLI::Simple::Utils qw(slurp);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use File::Basename qw(basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use MIME::Base64 qw(encode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 Readonly::Scalar our $CRLF => sprintf '%c%c', 0x0d, 0x0a;
18 2 Readonly::Scalar our $PAUSE_URL => 'https://pause.perl.org/pause/authenquery?ACTION=add_uri';
19  
20 ########################################################################
21 0 ▶sub cmd_publish_to_cpan {
Subroutine cmd_publish_to_cpan: not called CC=11 SCAR=48.8
Pod undocumented
22 ########################################################################
23 0 my ($self) = @_;
24  
25 0 my ( $file, $user, $pass ) = $self->get_args;
26 0 ▶ $user //= $ENV{PAUSE_USER};
Condition0%0/3
$user //= $ENV{"PAUSE_USER"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$user //= $ENV{"PAUSE_USER"}
$user $ENV{"PAUSE_USER"}
Truth table0%0/3
A //= B
A= $userB= $ENV{"PAUSE_USER"}
ABresult
1X1
011
000
27 0 ▶ $pass //= $ENV{PAUSE_PASSWORD};
Condition0%0/3
$pass //= $ENV{"PAUSE_PASSWORD"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$pass //= $ENV{"PAUSE_PASSWORD"}
$pass $ENV{"PAUSE_PASSWORD"}
Truth table0%0/3
A //= B
A= $passB= $ENV{"PAUSE_PASSWORD"}
ABresult
1X1
011
000
28  
29 0 ▶ die "ERROR: distribution file is required\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $file and -f $file 0 0 0
Condition0%0/3
$file and -f $file
!ll&&!rl&&r
000
MC/DC0%0/2
$file and -f $file
$file -f $file
Truth table0%0/3
A and B
A= $fileB= -f $file
ABresult
0X0
100
111
30 if !$file || !-f $file;
31  
32 0 ▶ die "ERROR: PAUSE username is required\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $user 0 0 0
33 if !$user;
34  
35 0 ▶ die "ERROR: PAUSE password is required\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $pass 0 0 0
36 if !$pass;
37  
38 0 ▶ open my $fh, '<:raw', $file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $file or die "ERROR: could not open $file\n$CPAN::Maker::Bootstrapper::Role::PAUSEUpload::OS_ERROR" 0 0 0
39 or die "ERROR: could not open $file\n$OS_ERROR";
40  
41 0 my $content = slurp($fh);
42 0 close $fh;
43  
44 0 my $filename = basename($file);
45  
46 0 my @fields = (
47 HIDDENNAME => uc $user,
48 CAN_MULTIPART => 1,
49 pause99_add_uri_upload => $filename,
50 pause99_add_uri_uri => q{},
51 SUBMIT_pause99_add_uri_httpupload => ' Upload this file from my disk ',
52 );
53  
54 # boundary must not occur in the payload
55 0 my $boundary;
56 0 ▶ do { $boundary = sprintf 'pause%08x%08x', rand 2**32, rand 2**32 } while index( $content, $boundary ) >= 0;
Branch: 1 branch
BranchTrueFalseTotal
index($content, $boundary) != -1 and do { do { $boundary = sprintf("pause%08x%08x", rand "4294967296", rand "4294967296") } } 0 0 0
57  
58 0 my $body = q{};
59  
60 0 ▶ while ( my ( $name, $value ) = splice @fields, 0, 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@fields, 0, 2)) 0 0 0
61 0 $body .= "--$boundary$CRLF" . qq{Content-Disposition: form-data; name="$name"$CRLF$CRLF} . "$value$CRLF";
62 }
63  
64 $body
65 0 .= "--$boundary$CRLF"
66 . qq{Content-Disposition: form-data; name="pause99_add_uri_httpupload"; filename="$filename"$CRLF}
67 . "Content-Type: application/gzip$CRLF$CRLF"
68 . $content
69 . $CRLF
70 . "--$boundary--$CRLF";
71  
72 0 my $res = HTTP::Tiny->new( verify_SSL => $TRUE, timeout => 30 )->request(
73 POST => $PAUSE_URL,
74 { headers => {
75 'Content-Type' => "multipart/form-data; boundary=$boundary",
76 'Authorization' => 'Basic ' . encode_base64( "$user:$pass", q{} ),
77 },
78 content => $body,
79 }
80 );
81  
82 die sprintf "ERROR: upload failed - %s %s\n", $res->{status}, $res->{reason}
83 0 ▶ if !$res->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"success"} 0 0 0
84  
85 0 print {*STDERR} "Successfully uploaded $file for PAUSE_USER $user\n";
86  
87 0 return $SUCCESS;
88 }
89  
90 2 1;
« CPAN/Maker/Bootstrapper/Role/DepsFilter.pm ↑ Summary Text/ASCIITable/FixANSI.pm »