File Coverage

blib/lib/Dist/Zilla/Plugin/Author/Plicease/Upload.pm
Criterion Covered Total %
statement 8 8 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 11 11 100.0


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::Author::Plicease::Upload 2.74 {
2              
3 1     1   1429 use 5.020;
  1         4  
4 1     1   7 use Moose;
  1         3  
  1         19  
5 1     1   7286 use Path::Tiny ();
  1         4  
  1         513  
6              
7             # ABSTRACT: Upload a dist to CPAN
8              
9              
10             extends 'Dist::Zilla::Plugin::UploadToCPAN';
11              
12             has cpan => (
13             is => 'ro',
14             default => sub { 1 },
15             );
16              
17             has url => (
18             is => 'ro',
19             default => sub { 'http://dist.wdlabs.com/' },
20             );
21              
22             around before_release => sub {
23             my $orig = shift;
24             my $self = shift;
25              
26             # don't check username / password here
27             # do it during release
28             };
29              
30             around release => sub {
31             my $orig = shift;
32             my $self = shift;
33             my($archive) = @_;
34              
35             my $local_release_dir = Path::Tiny->new("~/dev/site-dist/docs");
36              
37             my @cmd;
38              
39             if($self->cpan && $self->zilla->chrome->prompt_yn("upload to CPAN?"))
40             {
41             eval {
42             die "no username" unless length $self->username;
43             die "no password" unless length $self->password;
44             $self->$orig(@_);
45             };
46             if(my $error = $@)
47             {
48             $self->zilla->log("error uploading to cpan: $error");
49             $self->zilla->log("you will have to manually upload the dist");
50             }
51             return;
52             }
53             elsif(-d "$local_release_dir")
54             {
55             @cmd = ('cp', $archive, "$local_release_dir");
56             }
57             else
58             {
59             $self->zilla->log("no release process available, upload tarball manually");
60             }
61              
62             {
63             $self->zilla->log("% @cmd");
64             eval { system @cmd };
65             if(my $error = $@)
66             {
67             $self->zilla->log("NOTE COPY FAILED: $error");
68             $self->zilla->log("manual upload will be required");
69             }
70             else
71             {
72             $self->zilla->log("don't forget to commit and push to site-dist");
73             $self->zilla->log("download URL: " . $self->url . "$archive");
74             }
75             }
76              
77             return;
78             };
79              
80             __PACKAGE__->meta->make_immutable;
81              
82             }
83              
84             1;
85              
86             __END__
87              
88             =pod
89              
90             =encoding UTF-8
91              
92             =head1 NAME
93              
94             Dist::Zilla::Plugin::Author::Plicease::Upload - Upload a dist to CPAN
95              
96             =head1 VERSION
97              
98             version 2.74
99              
100             =head1 SYNOPSIS
101              
102             [Author::Plicease::Upload]
103             cpan = 1
104              
105             =head1 DESCRIPTION
106              
107             This works similar to L<Dist::Zilla::Plugin::UploadToCPAN>. Except:
108              
109             =over 4
110              
111             =item Non fatal
112              
113             It doesn't die if the upload does not succeed. In my work flow I usually
114             just upload the tarball manually when the upload fails. Sometimes I also
115             want to do the release step when I am not connected to the Internet.
116              
117             =item Asks first
118              
119             If C<cpan> is set to a true value, ask first before uploading to CPAN.
120             Sometimes and for some dists I instead commit it to a GitHub pages website
121             for internal use. If C<cpan> is set to a false value or if you deny
122             uploading to CPAN, the dist will be copied into the usual place where
123             the aforementioned GitHub pages repository is checked out.
124              
125             =back
126              
127             Basically just some personal preferences, you can and probably should
128             replace this with C<[UploadToCPAN]> if you are taking over a dist.
129              
130             =head1 OPTIONS
131              
132             =head2 cpan
133              
134             Either C<1> or C<0>. Set to C<0> and dist will not be uploaded to CPAN
135             on release.
136              
137             =head2 url
138              
139             Base web URL if CPAN upload is disabled.
140              
141             =head1 SEE ALSO
142              
143             =over 4
144              
145             =item L<Dist::Zilla>
146              
147             =item L<Dist::Zilla::PluginBundle::Author::Plicease>
148              
149             =back
150              
151             =head1 AUTHOR
152              
153             Graham Ollis <plicease@cpan.org>
154              
155             =head1 COPYRIGHT AND LICENSE
156              
157             This software is copyright (c) 2012-2022 by Graham Ollis.
158              
159             This is free software; you can redistribute it and/or modify it under
160             the same terms as the Perl 5 programming language system itself.
161              
162             =cut