blib/lib/Dist/Zilla/Plugin/GatherFile.pm

filter: Statementstmt 86.8% 53 / 61 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 86.6% 13 / 15 Podpod 0.0% 0 / 3 totaltotal 83.9% 73 / 87 CC 6 SCAR 7.9
CC
6
Cov
87%
gather_files
5.0
__ANON__
2.0
__ANON__
2.0
CRAP 2.2
« blib/lib/Dist/Zilla/Role/File.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/ModuleBuild.pm »
1 package Dist::Zilla::Plugin::GatherFile 6.040;
2 # ABSTRACT: gather individual file(s)
3  
4 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Dist::Zilla::Types qw(Path ArrayRefOfPaths);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 with 'Dist::Zilla::Role::FileGatherer';
7  
8 2 ▶use Dist::Zilla::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use MooseX::Types::Moose 'ArrayRef';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Dist::Zilla::File::OnDisk;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Dist::Zilla::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #pod =head1 SYNOPSIS
17 #pod
18 #pod [GatherFile]
19 #pod filename = examples/file.txt
20 #pod
21 #pod =head1 DESCRIPTION
22 #pod
23 #pod This is a very, very simple L<FileGatherer|Dist::Zilla::Role::FileGatherer>
24 #pod plugin. It adds all the files referenced by the C<filename> option that are
25 #pod found in the directory named in the L</root> attribute. If the root begins
26 #pod with a tilde, the tilde is passed through C<glob()> first.
27 #pod
28 #pod Since normally every distribution will use a GatherDir plugin, you would only
29 #pod need to use the GatherFile plugin if the file was already being excluded (e.g.
30 #pod from an C<exclude_match> configuration).
31 #pod
32 #pod =cut
33  
34 #pod =attr root
35 #pod
36 #pod This is the directory in which to look for files. If not given, it defaults to
37 #pod the dist root -- generally, the place where your F<dist.ini> or other
38 #pod configuration file is located.
39 #pod
40 #pod =cut
41  
42 has root => (
43 is => 'ro',
44 isa => Path,
45 lazy => 1,
46 coerce => 1,
47 required => 1,
48 3 ▶ default => sub { shift->zilla->root },
Subroutine __ANON__: called CC=1 SCAR=0.0
49 2 );
50  
51 #pod =attr prefix
52 #pod
53 #pod This parameter can be set to place the gathered files under a particular
54 #pod directory. See the L<description|DESCRIPTION> above for an example.
55 #pod
56 #pod =cut
57  
58 2 has prefix => (
59 is => 'ro',
60 isa => 'Str',
61 default => '',
62 );
63  
64 #pod =attr filename
65 #pod
66 #pod The name of the file to gather, relative to the C<root>.
67 #pod Can be used more than once.
68 #pod
69 #pod =cut
70  
71 has filenames => (
72 is => 'ro', isa => ArrayRefOfPaths,
73 lazy => 1,
74 coerce => 1,
75 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
76 2 );
77  
78 4 ▶sub mvp_aliases { +{ filename => 'filenames' } }
Subroutine mvp_aliases: called CC=1 SCAR=0.0
Pod undocumented
79 4 ▶sub mvp_multivalue_args { qw(filenames) }
Subroutine mvp_multivalue_args: called CC=1 SCAR=0.0
Pod undocumented
80  
81 0 ▶around dump_config => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
82 0 my $orig = shift;
83 0 my $self = shift;
84  
85 0 my $config = $self->$orig;
86  
87 $config->{+__PACKAGE__} = {
88 prefix => $self->prefix,
89 # only report relative to dist root to avoid leaking private info
90 root => path($self->root)->relative($self->zilla->root),
91 0 filenames => [ sort @{ $self->filenames } ],
92 };
93  
94 0 return $config;
95 2 };
96  
97 4 ▶sub gather_files {
Subroutine gather_files: called CC=5 SCAR=16.1
Pod undocumented
98 4 my ($self) = @_;
99  
100 4 my $repo_root = $self->zilla->root;
101 4 my $root = "" . $self->root;
102 0 $root =~ s{^~([\\/])}{ Dist::Zilla::Util->homedir . $1 }e;
103 4 $root = path($root);
104 4 ▶ $root = $root->absolute($repo_root) if path($root)->is_relative;
Branch: 1 branch
BranchTrueFalseTotal
if path($root)->is_relative 1 3 4
105  
106 4 for my $filename (@{ $self->filenames })
107 {
108 4 $filename = $root->child($filename);
109 4 ▶ $self->log_fatal("$filename is a directory! Use [GatherDir] instead?") if -d $filename;
Branch: 1 branch
BranchTrueFalseTotal
if -d $filename 0 4 4
110  
111 4 my $fileobj = $self->_file_from_filename($filename->stringify);
112  
113 3 $filename = $fileobj->name;
114 3 my $file = path($filename)->relative($root);
115 3 ▶ $file = path($self->prefix, $file) if $self->prefix;
Branch: 1 branch
BranchTrueFalseTotal
if $self->prefix 1 2 3
116  
117 3 $fileobj->name($file->stringify);
118 3 $self->add_file($fileobj);
119 }
120  
121 3 return;
122 }
123  
124 # as in GatherDir
125 4 ▶sub _file_from_filename {
Subroutine _file_from_filename: called CC=2 SCAR=6.9
126 4 my ($self, $filename) = @_;
127  
128 4 ▶ my @stat = stat $filename or $self->log_fatal("$filename does not exist!");
Branch: 1 branch
BranchTrueFalseTotal
my(@stat) = stat $filename or $self->log_fatal("$filename does not exist!") 3 1 4
129  
130 3 return Dist::Zilla::File::OnDisk->new({
131 name => $filename,
132 mode => $stat[2] & 0755, # kill world-writeability
133 });
134 }
135  
136 2 __PACKAGE__->meta->make_immutable;
137  
138 __END__
« blib/lib/Dist/Zilla/Role/File.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/ModuleBuild.pm »