| 1 | package Mojolicious::Command::Author::cpanify; | ||||||||||||||
| 2 | 1 | ▶ | use Mojo::Base 'Mojolicious::Command'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | |||||||||||||||
| 4 | 1 | ▶ | use Mojo::File qw(path); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 1 | ▶ | use Mojo::Util qw(getopt); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 1 | has description => 'Upload distribution to CPAN'; | |||||||||||||
| 8 | 1 | ▶ | has usage => sub { shift->extract_usage }; | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 2 | ▶ | sub run { | ||||||||||||
|
Subroutine
run: called CC=7 SCAR=27.5
Pod
documented
| |||||||||||||||
| 11 | 2 | my ($self, @args) = @_; | |||||||||||||
| 12 | |||||||||||||||
| 13 | 2 | ▶ | die $self->usage unless getopt \@args, | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 14 | 'p|password=s' => \(my $password = ''), | ||||||||||||||
| 15 | 'u|user=s' => \(my $user = ''); | ||||||||||||||
| 16 | 1 | ▶ | die $self->usage unless my $file = shift @args; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 17 | |||||||||||||||
| 18 | 1 | ▶ | my $tx = $self->app->ua->tap(sub { $_->proxy->detect })->post( | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 19 | "https://$user:$password\@pause.perl.org/pause/authenquery" => form => { | ||||||||||||||
| 20 | HIDDENNAME => $user, | ||||||||||||||
| 21 | CAN_MULTIPART => 1, | ||||||||||||||
| 22 | pause99_add_uri_upload => path($file)->basename, | ||||||||||||||
| 23 | SUBMIT_pause99_add_uri_httpupload => ' Upload this file from my disk ', | ||||||||||||||
| 24 | pause99_add_uri_uri => '', | ||||||||||||||
| 25 | pause99_add_uri_httpupload => {file => $file}, | ||||||||||||||
| 26 | } | ||||||||||||||
| 27 | ); | ||||||||||||||
| 28 | |||||||||||||||
| 29 | 1 | ▶ | if (my $err = $tx->error) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 30 | 0 | ▶ | my $code = $tx->res->code // 0; | ||||||||||||
|
Condition0%0/2
$tx->res->code // 0
MC/DC0%0/1
$tx->res->code // 0
$tx->res->code
Truth table0%0/2
A
A= $tx->res->code
| |||||||||||||||
| 31 | 0 | my $msg = $err->{message}; | |||||||||||||
| 32 | 0 | ▶ | if ($code == 401) { $msg = 'Wrong username or password.' } | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 33 | 0 | elsif ($code == 409) { $msg = 'File already exists on CPAN.' } | |||||||||||||
| 34 | 0 | die qq{Problem uploading file "$file": $msg\n}; | |||||||||||||
| 35 | } | ||||||||||||||
| 36 | |||||||||||||||
| 37 | 1 | say 'Upload successful!'; | |||||||||||||
| 38 | } | ||||||||||||||
| 39 | |||||||||||||||
| 40 | 1 | 1; | |||||||||||||
| 41 | |||||||||||||||
| 42 | =encoding utf8 | ||||||||||||||
| 43 | |||||||||||||||
| 44 | =head1 NAME | ||||||||||||||
| 45 | |||||||||||||||
| 46 | Mojolicious::Command::Author::cpanify - CPAN-ify command | ||||||||||||||
| 47 | |||||||||||||||
| 48 | =head1 SYNOPSIS | ||||||||||||||
| 49 | |||||||||||||||
| 50 | Usage: APPLICATION cpanify [OPTIONS] [FILE] | ||||||||||||||
| 51 | |||||||||||||||
| 52 | mojo cpanify -u sri -p secr3t Mojolicious-Plugin-MyPlugin-0.01.tar.gz | ||||||||||||||
| 53 | |||||||||||||||
| 54 | Options: | ||||||||||||||
| 55 | -h, --help Show this summary of available options | ||||||||||||||
| 56 | -p, --password <password> PAUSE password | ||||||||||||||
| 57 | -u, --user <name> PAUSE username | ||||||||||||||
| 58 | |||||||||||||||
| 59 | =head1 DESCRIPTION | ||||||||||||||
| 60 | |||||||||||||||
| 61 | L<Mojolicious::Command::Author::cpanify> uploads files to CPAN. | ||||||||||||||
| 62 | |||||||||||||||
| 63 | This is a core command, that means it is always enabled and its code a good example for learning to build new commands, | ||||||||||||||
| 64 | you're welcome to fork it. | ||||||||||||||
| 65 | |||||||||||||||
| 66 | See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are available by default. | ||||||||||||||
| 67 | |||||||||||||||
| 68 | =head1 ATTRIBUTES | ||||||||||||||
| 69 | |||||||||||||||
| 70 | L<Mojolicious::Command::Author::cpanify> inherits all attributes from L<Mojolicious::Command> and implements the | ||||||||||||||
| 71 | following new ones. | ||||||||||||||
| 72 | |||||||||||||||
| 73 | =head2 description | ||||||||||||||
| 74 | |||||||||||||||
| 75 | my $description = $cpanify->description; | ||||||||||||||
| 76 | $cpanify = $cpanify->description('Foo'); | ||||||||||||||
| 77 | |||||||||||||||
| 78 | Short description of this command, used for the command list. | ||||||||||||||
| 79 | |||||||||||||||
| 80 | =head2 usage | ||||||||||||||
| 81 | |||||||||||||||
| 82 | my $usage = $cpanify->usage; | ||||||||||||||
| 83 | $cpanify = $cpanify->usage('Foo'); | ||||||||||||||
| 84 | |||||||||||||||
| 85 | Usage information for this command, used for the help screen. | ||||||||||||||
| 86 | |||||||||||||||
| 87 | =head1 METHODS | ||||||||||||||
| 88 | |||||||||||||||
| 89 | L<Mojolicious::Command::Author::cpanify> inherits all methods from L<Mojolicious::Command> and implements the following | ||||||||||||||
| 90 | new ones. | ||||||||||||||
| 91 | |||||||||||||||
| 92 | =head2 run | ||||||||||||||
| 93 | |||||||||||||||
| 94 | $cpanify->run(@ARGV); | ||||||||||||||
| 95 | |||||||||||||||
| 96 | Run this command. | ||||||||||||||
| 97 | |||||||||||||||
| 98 | =head1 SEE ALSO | ||||||||||||||
| 99 | |||||||||||||||
| 100 | L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>. | ||||||||||||||
| 101 | |||||||||||||||
| 102 | =cut | ||||||||||||||