File Coverage

blib/lib/Dist/Zilla/Plugin/CopyFilesFromRelease.pm
Criterion Covered Total %
statement 30 30 100.0
branch 5 6 83.3
condition n/a
subroutine 7 7 100.0
pod 0 2 0.0
total 42 45 93.3


line stmt bran cond sub pod time code
1 1     1   3010826 use strict;
  1         3  
  1         31  
2 1     1   5 use warnings;
  1         2  
  1         56  
3             package Dist::Zilla::Plugin::CopyFilesFromRelease; # git description: v0.006-14-g6b0a6f6
4             # ABSTRACT: Copy files from a release (for SCM inclusion, etc.)
5             # KEYWORDS: plugin copy files repository distribution release
6              
7             our $VERSION = '0.007';
8              
9 1     1   6 use Moose;
  1         1  
  1         7  
10             with qw/ Dist::Zilla::Role::AfterRelease /;
11              
12 1     1   5730 use Path::Tiny 0.070;
  1         26  
  1         60  
13 1     1   8 use namespace::autoclean;
  1         2  
  1         9  
14              
15 1     1 0 538 sub mvp_multivalue_args { qw{ filename match } }
16              
17             has $_ => (
18             lazy => 1,
19             isa => 'ArrayRef[Str]',
20             default => sub { [] },
21             traits => ['Array'],
22             handles => { $_ => 'sort' },
23             ) foreach qw(filename match);
24              
25             around dump_config => sub {
26             my $orig = shift;
27             my $self = shift;
28              
29             my $config = $self->$orig;
30              
31             $config->{+__PACKAGE__} = {
32             map { $_ => [ $self->$_ ] } qw(filename match),
33             blessed($self) ne __PACKAGE__ ? ( version => $VERSION ) : (),
34             };
35              
36             return $config;
37             };
38              
39             sub after_release {
40 1     1 0 227640 my $self = shift;
41              
42 1         58 my $build_dir = $self->zilla->built_in;
43 1         92 my $root = $self->zilla->root;
44              
45 1         99 my $file_match = join '|', map quotemeta, $self->filename;
46 1         52 $file_match = join '|', '^(?:' . $file_match . ')$', $self->match;
47 1         55 $file_match = qr/$file_match/;
48              
49 1         56 my $iterator = path($build_dir)->iterator({ recurse => 1 });
50 1         171 while (my $file = $iterator->()) {
51 5 100       1143 next if -d $file;
52              
53 4         73 my $rel_path = $file->relative($build_dir);
54             next
55 4 100       921 unless $rel_path =~ $file_match;
56 2         23 my $dest = path($root, $rel_path);
57 2 50       72 $file->copy($dest)
58             or $self->log_fatal("Unable to copy $file to $dest: $!");
59 2         947 $self->log("Copied $file to $dest");
60             }
61             }
62              
63             __PACKAGE__->meta->make_immutable;
64              
65             __END__
66              
67             =pod
68              
69             =encoding UTF-8
70              
71             =for stopwords SCM
72              
73             =head1 NAME
74              
75             Dist::Zilla::Plugin::CopyFilesFromRelease - Copy files from a release (for SCM inclusion, etc.)
76              
77             =head1 VERSION
78              
79             version 0.007
80              
81             =head1 SYNOPSIS
82              
83             In your dist.ini:
84              
85             [CopyFilesFromRelease]
86             filename = README
87             match = ^MANIFEST*
88              
89             =head1 DESCRIPTION
90              
91             This plugin will automatically copy the files that you specify in
92             dist.ini from the build directory into the distribution directory.
93             This is so you can commit them to version control.
94              
95             =head1 SEE ALSO
96              
97             =over 4
98              
99             =item *
100              
101             L<Dist::Zilla::Plugin::CopyFilesFromBuild> - The basis for this module
102              
103             =back
104              
105             =head1 SUPPORT
106              
107             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Plugin-CopyFilesFromRelease>
108             (or L<bug-Dist-Zilla-Plugin-CopyFilesFromRelease@rt.cpan.org|mailto:bug-Dist-Zilla-Plugin-CopyFilesFromRelease@rt.cpan.org>).
109              
110             There is also a mailing list available for users of this distribution, at
111             L<http://dzil.org/#mailing-list>.
112              
113             There is also an irc channel available for users of this distribution, at
114             L<C<#distzilla> on C<irc.perl.org>|irc://irc.perl.org/#distzilla>.
115              
116             I am also usually active on irc, as 'ether' at C<irc.perl.org>.
117              
118             =head1 AUTHOR
119              
120             Graham Knop <haarg@haarg.org>
121              
122             =head1 CONTRIBUTORS
123              
124             =for stopwords Karen Etheridge Jonas B. Nielsen
125              
126             =over 4
127              
128             =item *
129              
130             Karen Etheridge <ether@cpan.org>
131              
132             =item *
133              
134             Jonas B. Nielsen <jonasbn@users.noreply.github.com>
135              
136             =back
137              
138             =head1 COPYRIGHT AND LICENCE
139              
140             This software is copyright (c) 2013 by Graham Knop.
141              
142             This is free software; you can redistribute it and/or modify it under
143             the same terms as the Perl 5 programming language system itself.
144              
145             =cut