blib/lib/Dist/Zilla/Plugin/UploadToCPAN.pm

filter: Statementstmt 93.4% 85 / 91 Branchbran 70.0% 14 / 20 Conditioncond 66.6% 8 / 12 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 79.1% 19 / 24 Podpod 0.0% 0 / 4 totaltotal 81.6% 129 / 158 CC 16 SCAR 10.1
CC
16
Cov
87%
__ANON__
5.5
__ANON__
4.7
before_release
4.0
CRAP 2.8
« blib/lib/Dist/Zilla/Prereqs.pm ↑ Summary blib/lib/Dist/Zilla/Role/FileMunger.pm »
1 package Dist::Zilla::Plugin::UploadToCPAN 6.040;
2 # ABSTRACT: upload the dist to CPAN
3  
4 9 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 with 'Dist::Zilla::Role::BeforeRelease',
6 'Dist::Zilla::Role::Releaser';
7  
8 9 ▶use Dist::Zilla::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 9 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use Dist::Zilla::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 9 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 9 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 #pod =head1 SYNOPSIS
19 #pod
20 #pod If loaded, this plugin will allow the F<release> command to upload to the CPAN.
21 #pod
22 #pod =head1 DESCRIPTION
23 #pod
24 #pod This plugin looks for configuration in your C<dist.ini> or (more
25 #pod likely) C<~/.dzil/config.ini>:
26 #pod
27 #pod [%PAUSE]
28 #pod username = YOUR-PAUSE-ID
29 #pod password = YOUR-PAUSE-PASSWORD
30 #pod
31 #pod If this configuration does not exist, it can read the configuration from
32 #pod C<~/.pause>, in the same format that L<cpan-upload> requires:
33 #pod
34 #pod user YOUR-PAUSE-ID
35 #pod password YOUR-PAUSE-PASSWORD
36 #pod
37 #pod If neither configuration exists, it will prompt you to enter your
38 #pod username and password during the BeforeRelease phase. Entering a
39 #pod blank username or password will abort the release.
40 #pod
41 #pod You can't put your password in your F<dist.ini>. C'mon now!
42 #pod
43 #pod =cut
44  
45 {
46 package
47 Dist::Zilla::Plugin::UploadToCPAN::_Uploader;
48 # CPAN::Uploader will be loaded later if used
49 9 our @ISA = 'CPAN::Uploader';
50 # Report CPAN::Uploader's version, not ours:
51 0 ▶ sub _ua_string { CPAN::Uploader->_ua_string }
Subroutine _ua_string: not called CC=1 SCAR=6.9
52  
53 6 ▶ sub log {
Subroutine log: called CC=1 SCAR=0.0
54 6 my $self = shift;
55 6 $self->{'Dist::Zilla'}{plugin}->log(@_);
56 }
57 }
58  
59 #pod =attr credentials_stash
60 #pod
61 #pod This attribute holds the name of a L<PAUSE stash|Dist::Zilla::Stash::Login>
62 #pod that will contain the credentials to be used for the upload. By default,
63 #pod UploadToCPAN will look for a C<%PAUSE> stash.
64 #pod
65 #pod =cut
66  
67 9 has credentials_stash => (
68 is => 'ro',
69 isa => 'Str',
70 default => '%PAUSE'
71 );
72  
73 has _credentials_stash_obj => (
74 is => 'ro',
75 isa => maybe_type( role_type('Dist::Zilla::Role::Stash::Login') ),
76 lazy => 1,
77 init_arg => undef,
78 5 ▶ default => sub { $_[0]->zilla->stash_named( $_[0]->credentials_stash ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
79 9 );
80  
81 8 ▶sub _credential {
Subroutine _credential: called CC=2 SCAR=6.9
82 8 my ($self, $name) = @_;
83  
84 8 ▶ return unless my $stash = $self->_credentials_stash_obj;
Branch: 1 branch
BranchTrueFalseTotal
unless my $stash = $self->_credentials_stash_obj 6 2 8
85 2 return $stash->$name;
86 }
87  
88 13 ▶sub mvp_aliases {
Subroutine mvp_aliases: called CC=1 SCAR=0.0
Pod undocumented
89 13 return { user => 'username' };
90 }
91  
92 #pod =attr username
93 #pod
94 #pod This option supplies the user's PAUSE username.
95 #pod It will be looked for in the user's PAUSE configuration; if not
96 #pod found, the user will be prompted.
97 #pod
98 #pod =cut
99  
100 has username => (
101 is => 'ro',
102 isa => 'Str',
103 lazy => 1,
104 4 ▶ default => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
105 4 my ($self) = @_;
106 return $self->_credential('username')
107 || $self->pause_cfg->{user}
108 4 ▶ || $self->zilla->chrome->prompt_str("PAUSE username: ");
Condition83%5/6
$self->_credential('username') || $self->pause_cfg->{'user'} || $self->zilla->chrome->prompt_str('PAUSE username: ')
l!l&&r!l&&!r
121
$self->_credential("username") or $self->pause_cfg->{"user"}
l!l&&r!l&&!r
103
MC/DC66%2/3
$self->_credential('username') || $self->pause_cfg->{'user'} || $self->zilla->chrome->prompt_str('PAUSE username: ')
$self->_credential("username") $self->pause_cfg->{"user"} $self->zilla->chrome->prompt_str('PAUSE username: ')
Truth table75%3/4
A or B || C
A= $self->_credential("username")B= $self->pause_cfg->{"user"}C= $self->zilla->chrome->prompt_str('PAUSE username: ')
ABCresult
1XX1
01X1
0011
0000
109 },
110 9 );
111  
112 0 ▶sub cpanid { shift->username }
Subroutine cpanid: not called CC=1 SCAR=6.9
Pod undocumented
113  
114 #pod =attr password
115 #pod
116 #pod This option supplies the user's PAUSE password. It cannot be provided via
117 #pod F<dist.ini>. It will be looked for in the user's PAUSE configuration; if not
118 #pod found, the user will be prompted.
119 #pod
120 #pod =cut
121  
122 has password => (
123 is => 'ro',
124 isa => 'Str',
125 init_arg => undef,
126 lazy => 1,
127 4 ▶ default => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
128 4 my ($self) = @_;
129 4 ▶ my $pw = $self->_credential('password') || $self->pause_cfg->{password};
Condition66%2/3
$self->_credential('password') || $self->pause_cfg->{'password'}
l!l&&r!l&&!r
103
MC/DC50%1/2
$self->_credential('password') || $self->pause_cfg->{'password'}
$self->_credential('password') $self->pause_cfg->{'password'}
Truth table66%2/3
A || B
A= $self->_credential('password')B= $self->pause_cfg->{'password'}
ABresult
1X1
011
000
130  
131 4 ▶ unless ($pw){
Branch: 1 branch
BranchTrueFalseTotal
unless ($pw) 3 1 4
132 3 my $uname = $self->username;
133 3 $pw = $self->zilla->chrome->prompt_str(
134 "PAUSE password for $uname: ",
135 { noecho => 1 },
136 );
137 }
138  
139 3 return $pw;
140 },
141 9 );
142  
143 #pod =attr pause_cfg_file
144 #pod
145 #pod This is the name of the file containing your pause credentials. It defaults
146 #pod F<.pause>. If you give a relative path, it is taken to be relative to
147 #pod L</pause_cfg_dir>.
148 #pod
149 #pod =cut
150  
151 has pause_cfg_file => (
152 is => 'ro',
153 isa => 'Str',
154 lazy => 1,
155 0 ▶ default => sub { '.pause' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
156 9 );
157  
158 #pod =attr pause_cfg_dir
159 #pod
160 #pod This is the directory for resolving a relative L</pause_cfg_file>.
161 #pod it defaults to the glob expansion of F<~>.
162 #pod
163 #pod =cut
164  
165 has pause_cfg_dir => (
166 is => 'ro',
167 isa => 'Str',
168 lazy => 1,
169 0 ▶ default => sub { Dist::Zilla::Util->homedir },
Subroutine __ANON__: not called CC=1 SCAR=6.9
170 9 );
171  
172 #pod =attr pause_cfg
173 #pod
174 #pod This is a hashref of defaults loaded from F<~/.pause> -- this attribute is
175 #pod subject to removal in future versions, as the config-loading behavior in
176 #pod CPAN::Uploader is improved.
177 #pod
178 #pod =cut
179  
180 has pause_cfg => (
181 is => 'ro',
182 isa => 'HashRef[Str]',
183 lazy => 1,
184 4 ▶ default => sub {
Subroutine __ANON__: called CC=4 SCAR=15.5
185 4 my $self = shift;
186 4 require CPAN::Uploader;
187 4 my $file = $self->pause_cfg_file;
188 4 ▶ $file = File::Spec->catfile($self->pause_cfg_dir, $file)
Branch: 1 branch
BranchTrueFalseTotal
unless "File::Spec"->file_name_is_absolute($file) 0 4 4
189 unless File::Spec->file_name_is_absolute($file);
190 4 ▶ return {} unless -e $file && -r _;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file and -r _ 0 4 4
Condition33%1/3
-e $file and -r _
!ll&&!rl&&r
004
MC/DC0%0/2
-e $file and -r _
-e $file -r _
Truth table33%1/3
A and B
A= -e $fileB= -r _
ABresult
0X0
100
111
191 4 ▶ my $cfg = try {
Subroutine __ANON__: called CC=1 SCAR=0.0
192 4 CPAN::Uploader->read_config_file($file)
193 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
194 0 $self->log("Couldn't load credentials from '$file': $_");
195 0 {};
196 4 };
197 4 return $cfg;
198 },
199 9 );
200  
201 #pod =attr subdir
202 #pod
203 #pod If given, this specifies a subdirectory under the user's home directory to
204 #pod which to upload. Using this option is not recommended.
205 #pod
206 #pod =cut
207  
208 9 has subdir => (
209 is => 'ro',
210 isa => 'Str',
211 predicate => 'has_subdir',
212 );
213  
214 #pod =attr upload_uri
215 #pod
216 #pod If given, this specifies an alternate URI for the PAUSE upload form. By
217 #pod default, the default supplied by L<CPAN::Uploader> is used. Using this option
218 #pod is not recommended in most cases.
219 #pod
220 #pod =cut
221  
222 9 has upload_uri => (
223 is => 'ro',
224 isa => 'Str',
225 predicate => 'has_upload_uri',
226 );
227  
228 #pod =attr retries
229 #pod
230 #pod The number of retries to perform on upload failure (5xx response). The default
231 #pod is set to 3 by this plugin. This option will be passed to L<CPAN::Uploader>.
232 #pod
233 #pod =cut
234  
235 9 has retries => (
236 is => 'ro',
237 isa => 'Int',
238 default => 3,
239 );
240  
241 #pod =attr retry_delay
242 #pod
243 #pod The number of seconds to wait between retries. The default is set to 5 seconds
244 #pod by this plugin. This option will be passed to L<CPAN::Uploader>.
245 #pod
246 #pod =cut
247  
248 9 has retry_delay => (
249 is => 'ro',
250 isa => 'Int',
251 default => 5,
252 );
253  
254 has uploader => (
255 is => 'ro',
256 isa => 'CPAN::Uploader',
257 lazy => 1,
258 2 ▶ default => sub {
Subroutine __ANON__: called CC=5 SCAR=17.0
259 2 my ($self) = @_;
260  
261 # Load the module lazily
262 2 require CPAN::Uploader;
263 2 CPAN::Uploader->VERSION('0.103004'); # require HTTPS
264  
265 2 ▶ my $uploader = Dist::Zilla::Plugin::UploadToCPAN::_Uploader->new({
Branch: 4 branches
BranchTrueFalseTotal
$self->has_subdir ? : 0 2 2
$self->has_upload_uri ? : 2 0 2
$self->retries ? : 2 0 2
$self->retry_delay ? : 2 0 2
266 user => $self->username,
267 password => $self->password,
268 ($self->has_subdir
269 ? (subdir => $self->subdir) : ()),
270 ($self->has_upload_uri
271 ? (upload_uri => $self->upload_uri) : ()),
272 ($self->retries
273 ? (retries => $self->retries) : ()),
274 ($self->retry_delay
275 ? (retry_delay => $self->retry_delay) : ()),
276 });
277  
278 2 $uploader->{'Dist::Zilla'}{plugin} = $self;
279 2 weaken $uploader->{'Dist::Zilla'}{plugin};
280  
281 2 return $uploader;
282 }
283 9 );
284  
285 5 ▶sub before_release {
Subroutine before_release: called CC=4 SCAR=13.9
Pod undocumented
286 5 my $self = shift;
287  
288 5 my $sentinel = [];
289  
290 5 for my $attr (qw(username password)) {
291 9 my $value;
292 9 my $ok = eval { $value = $self->$attr; 1 };
293  
294 9 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 1 8 9
295 1 $self->log_fatal([ "Couldn't figure out %s: %s", $attr, $@ ]);
296 }
297  
298 8 ▶ unless (length $value) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $value) 2 6 8
299 2 $self->log_fatal([ "No $attr was provided" ]);
300 }
301 }
302  
303 2 return;
304 }
305  
306 2 ▶sub release {
Subroutine release: called CC=1 SCAR=0.0
Pod undocumented
307 2 my ($self, $archive) = @_;
308  
309 2 $self->uploader->upload_file("$archive");
310 }
311  
312 9 __PACKAGE__->meta->make_immutable;
313 9 1;
314  
315 __END__
« blib/lib/Dist/Zilla/Prereqs.pm ↑ Summary blib/lib/Dist/Zilla/Role/FileMunger.pm »