| 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"}
MC/DC0%0/2
$user //= $ENV{"PAUSE_USER"}
$user
$ENV{"PAUSE_USER"}
Truth table0%0/3
A //= B
A= $userB= $ENV{"PAUSE_USER"}
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | $pass //= $ENV{PAUSE_PASSWORD}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$pass //= $ENV{"PAUSE_PASSWORD"}
MC/DC0%0/2
$pass //= $ENV{"PAUSE_PASSWORD"}
$pass
$ENV{"PAUSE_PASSWORD"}
Truth table0%0/3
A //= B
A= $passB= $ENV{"PAUSE_PASSWORD"}
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | die "ERROR: distribution file is required\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$file and -f $file
MC/DC0%0/2
$file and -f $file
$file
-f $file
Truth table0%0/3
A and B
A= $fileB= -f $file
| |||||||||||||||||||||||||||||
| 30 | if !$file || !-f $file; | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | die "ERROR: PAUSE username is required\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | if !$user; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | die "ERROR: PAUSE password is required\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | if !$pass; | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | open my $fh, '<:raw', $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | my $body = q{}; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | while ( my ( $name, $value ) = splice @fields, 0, 2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | print {*STDERR} "Successfully uploaded $file for PAUSE_USER $user\n"; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | return $SUCCESS; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 2 | 1; | |||||||||||||||||||||||||||