| 1 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package CPAN::Uploader 0.103017; | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: upload things to the CPAN | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | #pod =head1 ORIGIN | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | #pod This code is mostly derived from C<cpan-upload-http> by Brad Fitzpatrick, which | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | #pod in turn was based on C<cpan-upload> by Neil Bowers. I (I<rjbs>) didn't want to | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | #pod have to use a C<system> call to run either of those, so I refactored the code | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | #pod into this module. | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use File::Basename (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use HTTP::Request::Common qw(POST); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use HTTP::Status; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | my $UPLOAD_URI = $ENV{CPAN_UPLOADER_UPLOAD_URI} | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | || 'https://pause.perl.org/pause/authenquery?ACTION=add_uri'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'CPAN_UPLOADER_UPLOAD_URI'} || 'https://pause.perl.org/pause/authenquery?ACTION=add_uri'
MC/DC0%0/1
$ENV{'CPAN_UPLOADER_UPLOAD_URI'} || 'https://pause.perl.org/pause/authenquery?ACTION=add_uri'
$ENV{'CPAN_UPLOADER_UPLOAD_URI'}
Truth table50%1/2
A
A= $ENV{'CPAN_UPLOADER_UPLOAD_URI'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | #pod =method upload_file | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | #pod CPAN::Uploader->upload_file($file, \%arg); | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | #pod $uploader->upload_file($file); | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | #pod Valid arguments are: | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | #pod user - (required) your CPAN / PAUSE id | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | #pod password - (required) your CPAN / PAUSE password | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | #pod subdir - the directory (under your home directory) to upload to | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | #pod http_proxy - uri of the http proxy to use | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | #pod upload_uri - uri of the upload handler; usually the default (PAUSE) is right | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | #pod debug - if set to true, spew lots more debugging output | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | #pod retries - number of retries to perform on upload failure (5xx response) | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | #pod retry_delay - number of seconds to wait between retries | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | #pod This method attempts to actually upload the named file to the CPAN. It will | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | #pod raise an exception on error. c<upload_uri> can also be set through the ENV | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | #pod variable c<CPAN_UPLOADER_UPLOAD_URI>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | sub upload_file { | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my ($self, $file, $arg) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upload_file: not called CC=18 SCAR=58.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | Carp::confess(q{don't supply %arg when calling upload_file on an object}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$arg and ref $self
MC/DC0%0/2
$arg and ref $self
$arg
ref $self
Truth table0%0/3
A and B
A= $argB= ref $self
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | if $arg and ref $self; | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | Carp::confess(q{attempted to upload a non-file}) unless -f $file; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # class call with no args is no good | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | Carp::confess(q{need to supply %arg when calling upload_file from the class}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $self or $arg
MC/DC0%0/2
ref $self or $arg
ref $self
$arg
Truth table0%0/3
A or B
A= ref $selfB= $arg
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | if not (ref $self) and not $arg; | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $self = $self->new($arg) if $arg; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($arg->{dry_run}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $self->log("By request, cowardly refusing to do anything at all."); | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $self->log( | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | "The following arguments would have been used to upload: \n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | . '$self: ' . Data::Dumper::Dumper($self) | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | . '$file: ' . Data::Dumper::Dumper($file) | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | my $retries = $self->{retries} || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'retries'} || 0
MC/DC0%0/1
$self->{'retries'} || 0
$self->{'retries'}
Truth table0%0/2
A
A= $self->{'retries'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | my $tries = ($retries > 0) ? $retries + 1 : 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | TRY: for my $try (1 .. $tries) { | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | last TRY if eval { $self->_upload($file); 1 }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | die $@ unless $@ !~ /request failed with error code 5/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ($try <= $tries) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $self->log("Upload failed ($@)"); | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if ($tries and ($try < $tries)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$tries and $try < $tries
MC/DC0%0/2
$tries and $try < $tries
$tries
$try < $tries
Truth table0%0/3
A and B
A= $triesB= $try < $tries
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $next_try = $try + 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $self->log("Will make attempt #$next_try ..."); | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sleep $self->{retry_delay} if $self->{retry_delay}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ($try >= $tries) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | die "Failed to upload and reached maximum retry count!\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | sub _ua_string { | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ua_string: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | my $version = defined $class->VERSION ? $class->VERSION : 'dev'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | return "$class/$version"; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub uri { shift->{upload_uri} || $UPLOAD_URI } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uri: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub target { shift->{target} || 'PAUSE' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
target: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | sub _upload { | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_upload: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $self->log("registering upload with " . $self->target . " web server"); | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $agent = LWP::UserAgent->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $agent->agent( $self->_ua_string ); | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $agent->env_proxy; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | $agent->proxy(http => $self->{http_proxy}) if $self->{http_proxy}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | my $uri = $self->{upload_uri} || $UPLOAD_URI; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'upload_uri'} || $UPLOAD_URI
MC/DC0%0/2
$self->{'upload_uri'} || $UPLOAD_URI
$self->{'upload_uri'}
$UPLOAD_URI
Truth table0%0/3
A || B
A= $self->{'upload_uri'}B= $UPLOAD_URI
| |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $type = 'form-data'; | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | my %content = ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | HIDDENNAME => $self->{user}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | ($self->{subdir} ? (pause99_add_uri_subdirtext => $self->{subdir}) : ()), | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if ($file =~ m{^https?://}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $type = 'application/x-www-form-urlencoded'; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | %content = ( | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | %content, | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | pause99_add_uri_httpupload => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | pause99_add_uri_uri => $file, | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | SUBMIT_pause99_add_uri_uri => " Upload this URL ", | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | %content = ( | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | %content, | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | CAN_MULTIPART => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | pause99_add_uri_upload => File::Basename::basename($file), | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | pause99_add_uri_httpupload => [ $file ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | pause99_add_uri_uri => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | SUBMIT_pause99_add_uri_httpupload => " Upload this file from my disk ", | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $request = POST( | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | $uri, | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | Content_Type => $type, | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | Content => \%content, | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $request->authorization_basic($self->{user}, $self->{password}); | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | my $DEBUG_METHOD = $ENV{CPAN_UPLOADER_DISPLAY_HTTP_BODY} | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | ? 'as_string' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | : 'headers_as_string'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | $self->log_debug( | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | "----- REQUEST BEGIN -----\n" . | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | $request->$DEBUG_METHOD . "\n" . | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | "----- REQUEST END -------\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # Make the request to the PAUSE web server | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $self->log("POSTing upload for $file to $uri"); | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | my $response = $agent->request($request); | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # So, how'd we do? | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if (not defined $response) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | die "Request completely failed - we got undef back: $!"; | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | if ($response->is_error) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | if ($response->code == RC_NOT_FOUND) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | die "PAUSE's CGI for handling messages seems to have moved!\n", | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | "(HTTP response code of 404 from the ", $self->target, " web server)\n", | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | "It used to be: ", $uri, "\n", | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | "Please inform the maintainer of $self.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | die "request failed with error code ", $response->code, | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | "\n Message: ", $response->message, "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $self->log_debug($_) for ( | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | "Looks OK!", | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | "----- RESPONSE BEGIN -----\n" . | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | $response->$DEBUG_METHOD . "\n" . | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | "----- RESPONSE END -------\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $self->log($self->target . " add message sent ok [" . $response->code . "]"); | |||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | #pod =method new | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | #pod my $uploader = CPAN::Uploader->new(\%arg); | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | #pod This method returns a new uploader. You probably don't need to worry about | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | #pod this method. | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | #pod Valid arguments are the same as those to C<upload_file>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | my ($class, $arg) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | $arg->{$_} or Carp::croak("missing $_ argument") for qw(user password); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | bless $arg => $class; | |||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | #pod =method read_config_file | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | #pod my $config = CPAN::Uploader->read_config_file( $filename ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | #pod This reads the config file and returns a hashref of its contents that can be | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | #pod used as configuration for CPAN::Uploader. | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | #pod If no filename is given, it looks for F<.pause> in the user's home directory | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | #pod (from the env var C<HOME>, or the current directory if C<HOME> isn't set). | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | #pod See L<cpan-upload/CONFIGURATION> for the config format. | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | sub read_config_file { | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | my ($class, $filename) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_config_file: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | unless (defined $filename) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | my $home = $^O eq 'MSWin32' && "$]" < 5.016 | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | ? $ENV{HOME} || $ENV{USERPROFILE} | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | : (<~>)[0]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$^O eq "MSWin32" and "$]" < "5.016"
$ENV{"HOME"} or $ENV{"USERPROFILE"}
MC/DC0%0/2
$^O eq "MSWin32" and "$]" < "5.016"
$^O eq "MSWin32"
"$]" < "5.016"
MC/DC0%0/2
$ENV{"HOME"} or $ENV{"USERPROFILE"}
$ENV{"HOME"}
$ENV{"USERPROFILE"}
Truth table0%0/3
A and B
A= $^O eq "MSWin32"B= "$]" < "5.016"
Truth table0%0/3
A or B
A= $ENV{"HOME"}B= $ENV{"USERPROFILE"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $filename = File::Spec->catfile($home, '.pause'); | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | return {} unless -e $filename and -r _; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-e $filename and -r _
MC/DC0%0/2
-e $filename and -r _
-e $filename
-r _
Truth table0%0/3
A and B
A= -e $filenameB= -r _
| |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my %conf; | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | if ( eval { require Config::Identity } ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | %conf = Config::Identity->load($filename); | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | $conf{user} = delete $conf{username} unless $conf{user}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | else { # Process .pause manually | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | open my $pauserc, '<', $filename | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | or die "can't open $filename for reading: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | while (<$pauserc>) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | if (/BEGIN PGP MESSAGE/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | Carp::croak "$filename seems to be encrypted. " | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | . "Maybe you need to install Config::Identity?" | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | next unless $_ and $_ !~ /^\s*#/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_ and not $_ =~ /^\s*#/
MC/DC0%0/2
$_ and not $_ =~ /^\s*#/
$_
not $_ =~ /^\s*#/
Truth table0%0/3
A and not(B)
A= $_B= not $_ =~ /^\s*#/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my ($k, $v) = /^\s*(\w+)\s+(.+)$/; | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | Carp::croak "multiple entries for $k" if $conf{$k}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $conf{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # minimum validation of arguments | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | Carp::croak "Configured user has trailing whitespace" | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | if defined $conf{user} && $conf{user} =~ /\s$/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $conf{"user"} and $conf{"user"} =~ /\s$/
MC/DC0%0/2
defined $conf{"user"} and $conf{"user"} =~ /\s$/
defined $conf{"user"}
$conf{"user"} =~ /\s$/
Truth table0%0/3
A and B
A= defined $conf{"user"}B= $conf{"user"} =~ /\s$/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | Carp::croak "Configured user contains whitespace" | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | if defined $conf{user} && $conf{user} =~ /\s/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $conf{"user"} and $conf{"user"} =~ /\s/
MC/DC0%0/2
defined $conf{"user"} and $conf{"user"} =~ /\s/
defined $conf{"user"}
$conf{"user"} =~ /\s/
Truth table0%0/3
A and B
A= defined $conf{"user"}B= $conf{"user"} =~ /\s/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | return \%conf; | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | #pod =method log | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | #pod $uploader->log($message); | ||||||||||||||||||||||||||||||||||||||||||||||
| 273 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | #pod This method logs the given string. The default behavior is to print it to the | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | #pod screen. The message should not end in a newline, as one will be added as | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | #pod needed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 277 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | sub log { | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | print "$_[0]\n" | |||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | #pod =method log_debug | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | #pod This method behaves like C<L</log>>, but only logs the message if the | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | #pod CPAN::Uploader is in debug mode. | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | sub log_debug { | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_debug: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | return unless $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | $self->log($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||