File Coverage

blib/lib/Dist/Zilla/Plugin/ArchiveRelease.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             #---------------------------------------------------------------------
2             package Dist::Zilla::Plugin::ArchiveRelease;
3             #
4             # Copyright 2010 Christopher J. Madsen
5             #
6             # Author: Christopher J. Madsen <perl@cjmweb.net>
7             # Created: 6 Mar 2010
8             #
9             # This program is free software; you can redistribute it and/or modify
10             # it under the same terms as Perl itself.
11             #
12             # This program is distributed in the hope that it will be useful,
13             # but WITHOUT ANY WARRANTY; without even the implied warranty of
14             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the
15             # GNU General Public License or the Artistic License for more details.
16             #
17             # ABSTRACT: Move the release tarball to an archive directory
18             #---------------------------------------------------------------------
19              
20 1     1   743 use 5.008;
  1         2  
  1         44  
21             our $VERSION = '4.26';
22             # This file is part of Dist-Zilla-Plugins-CJM 4.26 (December 13, 2014)
23              
24              
25 1     1   284 use Moose;
  0            
  0            
26             with 'Dist::Zilla::Role::BeforeRelease';
27             with 'Dist::Zilla::Role::Releaser';
28             with 'Dist::Zilla::Role::FilePruner';
29              
30             use Path::Class ();
31             #---------------------------------------------------------------------
32              
33              
34             has _directory => (
35             is => 'ro',
36             isa => 'Str',
37             default => 'releases',
38             init_arg => 'directory',
39             writer => '_set_directory',
40             );
41              
42             sub directory
43             {
44             my $self = shift;
45              
46             my $dir = $self->_directory;
47              
48             # Convert ~ to home directory:
49             if ($dir =~ /^~/) {
50             require File::HomeDir;
51             File::HomeDir->VERSION(0.81);
52              
53             $dir =~ s/^~(\w+)/ File::HomeDir->users_home("$1") /e;
54             $dir =~ s/^~/ File::HomeDir->my_home /e;
55              
56             $self->_set_directory($dir);
57             } # end if $dir begins with ~
58              
59             Path::Class::dir($dir)->absolute($self->zilla->root);
60             } # end get_directory
61              
62             #---------------------------------------------------------------------
63             # Format a path for display:
64              
65             sub pretty_path
66             {
67             my ($self, $path) = @_;
68              
69             my $root = $self->zilla->root;
70              
71             $path = $path->relative($root) if $root->subsumes($path);
72              
73             "$path";
74             } # end pretty_path
75              
76             #---------------------------------------------------------------------
77             # Don't distribute previously archived releases:
78              
79             sub prune_files
80             {
81             my $self = shift;
82              
83             my $root = $self->zilla->root;
84             my $dir = $self->directory;
85              
86             if ($root->subsumes($dir)) {
87             $dir = $dir->relative($root);
88             my $files = $self->zilla->files;
89              
90             @$files = grep { not $dir->subsumes($_->name) } @$files;
91             } # end if archive directory is inside root
92              
93             return;
94             } # end prune_files
95              
96             #---------------------------------------------------------------------
97             sub before_release
98             {
99             my ($self, $tgz) = @_;
100              
101             my $dir = $self->directory;
102              
103             # If the directory doesn't exist, create it:
104             unless (-d $dir) {
105             my $dirR = $self->pretty_path($dir);
106              
107             mkdir $dir or $self->log_fatal("Unable to create directory $dirR: $!");
108             $self->log("Created directory $dirR");
109             }
110              
111             # If the tarball has already been archived, abort:
112             my $file = $dir->file($tgz->basename);
113              
114             $self->log_fatal($self->pretty_path($file) . " already exists")
115             if -e $file;
116             } # end before_release
117              
118             #---------------------------------------------------------------------
119             # Main entry point:
120              
121             sub release
122             {
123             my ($self, $tgz) = @_;
124              
125             chmod(0444, $tgz);
126              
127             my $dest = $self->directory->file($tgz->basename);
128             my $destR = $self->pretty_path($dest);
129              
130             require File::Copy;
131             File::Copy::move($tgz, $dest)
132             or $self->log_fatal("Failed to move to $destR: $!");
133              
134             $self->log("Moved to $destR");
135             } # end release
136              
137             #---------------------------------------------------------------------
138             no Moose;
139             __PACKAGE__->meta->make_immutable;
140             1;
141              
142             __END__
143              
144             =head1 NAME
145              
146             Dist::Zilla::Plugin::ArchiveRelease - Move the release tarball to an archive directory
147              
148             =head1 VERSION
149              
150             This document describes version 4.26 of
151             Dist::Zilla::Plugin::ArchiveRelease, released December 13, 2014
152             as part of Dist-Zilla-Plugins-CJM version 4.26.
153              
154             =head1 SYNOPSIS
155              
156             In your F<dist.ini>:
157              
158             [ArchiveRelease]
159             directory = releases ; this is the default
160              
161             =head1 DESCRIPTION
162              
163             If included, this plugin will cause the F<release> command to mark the
164             tarball read-only and move it to an archive directory. You can
165             combine this with another Releaser plugin (like
166             L<UploadToCPAN|Dist::Zilla::Plugin::UploadToCPAN>), but it must be the
167             last Releaser in your config (or the other Releasers won't be able to
168             find the file being released).
169              
170             It also acts as a FilePruner in order to prevent Dist::Zilla from
171             including the archived releases in future builds.
172              
173             =head1 ATTRIBUTES
174              
175             =head2 directory
176              
177             The directory to which the tarball will be moved. It may begin with
178             C<~> (or C<~user>) to mean your (or some other user's) home directory.
179             Defaults to F<releases>.
180             If the directory doesn't exist, it will be created during the
181             BeforeRelease phase.
182              
183             All files inside this directory will be pruned from the distribution.
184              
185              
186             =for Pod::Coverage
187             before_release
188             release
189             pretty_path
190             prune_files
191              
192             =head1 INCOMPATIBILITIES
193              
194             None reported.
195              
196             =head1 BUGS AND LIMITATIONS
197              
198             No bugs have been reported.
199              
200             =head1 AUTHOR
201              
202             Christopher J. Madsen S<C<< <perl AT cjmweb.net> >>>
203              
204             Please report any bugs or feature requests
205             to S<C<< <bug-Dist-Zilla-Plugins-CJM AT rt.cpan.org> >>>
206             or through the web interface at
207             L<< http://rt.cpan.org/Public/Bug/Report.html?Queue=Dist-Zilla-Plugins-CJM >>.
208              
209             You can follow or contribute to Dist-Zilla-Plugins-CJM's development at
210             L<< https://github.com/madsen/dist-zilla-plugins-cjm >>.
211              
212             =head1 COPYRIGHT AND LICENSE
213              
214             This software is copyright (c) 2014 by Christopher J. Madsen.
215              
216             This is free software; you can redistribute it and/or modify it under
217             the same terms as the Perl 5 programming language system itself.
218              
219             =head1 DISCLAIMER OF WARRANTY
220              
221             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
222             FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
223             OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
224             PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
225             EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
226             WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
227             ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
228             YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
229             NECESSARY SERVICING, REPAIR, OR CORRECTION.
230              
231             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
232             WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
233             REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE
234             LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
235             OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
236             THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
237             RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
238             FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
239             SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
240             SUCH DAMAGES.
241              
242             =cut