File Coverage

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


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