| 1 | package CPAN::Upload::Tiny; | ||||||||||||||||||||||||||||
| 2 | 1 | $CPAN::Upload::Tiny::VERSION = '0.009'; | |||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use File::Basename (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use MIME::Base64 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use HTTP::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use HTTP::Tiny::Multipart; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | my $UPLOAD_URI = $ENV{CPAN_UPLOADER_UPLOAD_URI} || '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'}
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub new { | ||||||||||||||||||||||||||||
| 15 | 0 | ▶ | my ($class, $user, $password) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | Carp::croak('No user set') if not defined $user; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | Carp::croak('No password set') if not defined $password; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 0 | return bless { | |||||||||||||||||||||||||||
| 19 | user => $user, | ||||||||||||||||||||||||||||
| 20 | password => $password, | ||||||||||||||||||||||||||||
| 21 | }, $class; | ||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | sub new_from_config { | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my ($class, $filename) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new_from_config: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 0 | return $class->new(read_config_file($filename)); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | my $has_readkey = eval { require Term::ReadKey }; | |||||||||||||||||||||||||||
| 30 | 1 | ▶ | *read_key = $has_readkey ? \&Term::ReadKey::ReadMode : sub {}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub prompt { | ||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my ($mess, $mode) = @_; | ||||||||||||||||||||||||||
|
Subroutine
prompt: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | local $| = 1; | |||||||||||||||||||||||||||
| 36 | 0 | local $\; | |||||||||||||||||||||||||||
| 37 | 0 | print "$mess? "; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | read_key($mode); | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | my $ans = <STDIN> // ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
readline STDIN // ""
MC/DC0%0/1
readline STDIN // ""
readline STDIN
Truth table0%0/2
A
A= readline STDIN
| |||||||||||||||||||||||||||||
| 41 | 0 | read_key(0); | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | print "\n" if $mode > 1 && $has_readkey; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mode > 1 and $has_readkey
MC/DC0%0/2
$mode > 1 and $has_readkey
$mode > 1
$has_readkey
Truth table0%0/3
A and B
A= $mode > 1B= $has_readkey
| |||||||||||||||||||||||||||||
| 43 | 0 | chomp $ans; | |||||||||||||||||||||||||||
| 44 | 0 | return $ans; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub new_from_config_or_stdin { | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my ($class, $filename) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new_from_config_or_stdin: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 49 | 0 | my ($user, $pass) = read_config_file($filename); | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | $user ||= prompt("What is your PAUSE ID", 1); | ||||||||||||||||||||||||||
|
Condition0%0/3
$user ||= prompt("What is your PAUSE ID", 1)
MC/DC0%0/2
$user ||= prompt("What is your PAUSE ID", 1)
$user
prompt("What is your PAUSE ID", 1)
Truth table0%0/3
A ||= B
A= $userB= prompt("What is your PAUSE ID", 1)
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | $pass ||= prompt("What is your PAUSE password", 2); | ||||||||||||||||||||||||||
|
Condition0%0/3
$pass ||= prompt("What is your PAUSE password", 2)
MC/DC0%0/2
$pass ||= prompt("What is your PAUSE password", 2)
$pass
prompt("What is your PAUSE password", 2)
Truth table0%0/3
A ||= B
A= $passB= prompt("What is your PAUSE password", 2)
| |||||||||||||||||||||||||||||
| 52 | 0 | return $class->new($user, $pass); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub upload_file { | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my ($self, $filename) = @_; | ||||||||||||||||||||||||||
|
Subroutine
upload_file: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | open my $fh, '<:raw', $filename or die "Could not open $filename: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | my $content = do { local $/; <$fh> }; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | my $tiny = HTTP::Tiny->new(verify_SSL => 1); | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | my $auth = 'Basic ' . MIME::Base64::encode("$self->{user}:$self->{password}", ''); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | my $result = $tiny->post_multipart($UPLOAD_URI, { | ||||||||||||||||||||||||||||
| 66 | HIDDENNAME => $self->{user}, | ||||||||||||||||||||||||||||
| 67 | 0 | CAN_MULTIPART => 1, | |||||||||||||||||||||||||||
| 68 | pause99_add_uri_httpupload => { | ||||||||||||||||||||||||||||
| 69 | filename => File::Basename::basename($filename), | ||||||||||||||||||||||||||||
| 70 | content => $content, | ||||||||||||||||||||||||||||
| 71 | content_type => 'application/gzip', | ||||||||||||||||||||||||||||
| 72 | }, | ||||||||||||||||||||||||||||
| 73 | pause99_add_uri_uri => '', | ||||||||||||||||||||||||||||
| 74 | SUBMIT_pause99_add_uri_httpupload => ' Upload this file from my disk ', | ||||||||||||||||||||||||||||
| 75 | }, { headers => { Authorization => $auth } }); | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if (!$result->{success}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | my $key = $result->{status} == 599 ? 'content' : 'reason'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | die "Upload failed: $result->{$key}\n"; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | return; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sub read_config_file { | ||||||||||||||||||||||||||||
| 86 | 1 | ▶ | my $filename = shift || glob('~/.pause'); | ||||||||||||||||||||||||||
|
Subroutine
read_config_file: called CC=12 SCAR=29.8
Pod
undocumented
Condition33%1/3
shift() || glob('~/.pause')
MC/DC0%0/2
shift() || glob('~/.pause')
shift()
glob('~/.pause')
Truth table33%1/3
A || B
A= shift()B= glob('~/.pause')
| |||||||||||||||||||||||||||||
| 87 | 1 | ▶ | return unless -r $filename; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | my %conf; | |||||||||||||||||||||||||||
| 90 | 1 | ▶ | if ( eval { require Config::Identity } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | %conf = Config::Identity->load($filename); | |||||||||||||||||||||||||||
| 92 | 0 | ▶ | $conf{user} = delete $conf{username} unless $conf{user}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | else { # Process .pause manually | ||||||||||||||||||||||||||||
| 95 | 1 | ▶ | open my $pauserc, '<', $filename or die "can't open $filename for reading: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 1 | ▶ | while (<$pauserc>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 2 | chomp; | |||||||||||||||||||||||||||
| 99 | 2 | ▶ | Carp::croak "$filename seems to be encrypted. Maybe you need to install Config::Identity?" if /BEGIN PGP MESSAGE/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 2 | ▶ | next if not length or $_ =~ /^\s*#/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not length $_ or $_ =~ /^\s*#/
MC/DC0%0/2
not length $_ or $_ =~ /^\s*#/
not length $_
$_ =~ /^\s*#/
Truth table33%1/3
not(A) or B
A= not length $_B= $_ =~ /^\s*#/
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 2 | ▶ | if (my ($k, $v) = / ^ \s* (user|password) \s+ (.+?) \s* $ /x) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 2 | ▶ | Carp::croak "Multiple entries for $k" if $conf{$k}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 2 | $conf{$k} = $v; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 1 | return @conf{'user', 'password'}; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 1 | 1; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | #ABSTRACT: A tiny CPAN uploader | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | __END__ | ||||||||||||||||||||||||||||