blib/lib/Dist/Zilla/Plugin/ManifestInRoot.pm untested

filter: Statementstmt 0.0% 0 / 56 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 73 CC 1 SCAR 6.9
CC
1
Cov
0%
after_build
2.0
before_build
2.0
gather_files
2.0
CRAP 2.0
1 package Dist::Zilla::Plugin::ManifestInRoot;
2  
3 use namespace::autoclean;
4 use version; our $VERSION = qv( sprintf '0.16.%d', q$Rev: 1 $ =~ /\d+/gmx );
5  
6 use Moose;
7 use Dist::Zilla::File::FromCode;
8 use File::Spec::Functions qw( catfile );
9 use Path::Tiny qw( path );
10  
11 with 'Dist::Zilla::Role::AfterBuild';
12 with 'Dist::Zilla::Role::BeforeBuild';
13 with 'Dist::Zilla::Role::FileGatherer';
14  
15 # Public attributes
16 has 'excludes' => is => 'ro', traits => [ 'Array' ],
17 default => sub { [ qw( LICENSE META.json META.yml README SIGNATURE
18 t/00report-metadata.dd t/00report-metadata.t ) ]},
19 handles => { 'excluding' => 'elements', }, init_arg => 'exclude';
20  
21 # Private functions
22 my $_fix_filename = sub {
23 my $name = shift; $name =~ m{ [ \'\\] }mx or return $name;
24  
25 $name =~ s{ \\ }{\\\\}gmx; $name =~ s{ ' }{\\'}gmx;
26  
27 return qq{'$name'};
28 };
29  
30 # Public methods
31 sub after_build {
32 my ($self, $args) = @_;
33  
34 my $excluding = join '|', $self->excluding;
35 my $from = path( $args->{build_root}, 'MANIFEST' );
36 my @lines = grep { not m{ \A (?: $excluding ) \r?\n \z }mx }
37 $from->lines;
38 my $to = path( $self->zilla->root, 'MANIFEST' );
39  
40 $to->spew( @lines );
41  
42 return;
43 }
44  
45 sub before_build {
46 my $self = shift; unlink catfile( $self->zilla->root, 'MANIFEST' ); return;
47 }
48  
49 sub gather_files {
50 my ($self, $arg) = @_; my $zilla = $self->zilla;
51  
52 my $file = Dist::Zilla::File::FromCode->new( {
53 name => 'MANIFEST',
54 code => sub {
55 (join "\n", map { $_fix_filename->( $_ ) }
56 sort map { $_->name } @{ $zilla->files } )."\n";
57 },
58 } );
59  
60 $self->add_file( $file );
61 return;
62 }
63  
64 sub mvp_multivalue_args {
65 return qw( exclude );
66 }
67  
68 1;
69  
70 __END__