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

filter: Statementstmt 62.5% 30 / 48 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 72.7% 8 / 11 Podpod 0.0% 0 / 3 totaltotal 55.8% 38 / 68 CC 6 SCAR 20.6
CC
6
Cov
56%
prune_files
20.0
munge_files
12.0
munge_file
2.0
CRAP 7.9
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Dist::Zilla::Plugin::AppendExternalData;
4 # ABSTRACT: Append data to gathered files
5 1 our $VERSION = '0.003'; # VERSION
6  
7 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Moose::Autobox;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use MooseX::Types::Path::Class qw(Dir File);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 with(
11 'Dist::Zilla::Role::FileMunger',
12 'Dist::Zilla::Role::FilePruner',
13 'Dist::Zilla::Role::FileFinderUser' => {
14 default_finders => [ ':InstallModules', ':ExecFiles' ],
15 },
16 );
17  
18  
19 1 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 1 has source_dir => (
24 is => 'ro',
25 isa => Dir,
26 coerce => 1,
27 required => 1,
28 );
29  
30  
31 1 has prune_source_dir => (
32 is => 'ro',
33 isa => 'Bool',
34 default => 1,
35 );
36  
37 0 ▶sub prune_files {
Subroutine prune_files: not called CC=4 SCAR=30.0
Pod undocumented
38 0 my ($self) = @_;
39  
40 0 ▶ return unless $self->prune_source_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->prune_source_dir 0 0 0
41  
42 0 my $source_dir = $self->source_dir;
43  
44 0 for my $file ($self->zilla->files->flatten) {
45 0 ▶ next unless $file->name =~ m{\A$source_dir/};
Branch: 1 branch
BranchTrueFalseTotal
unless $file->name =~ m[\A$source_dir/] 0 0 0
46 0 $self->log_debug([ 'pruning %s', $file->name ]);
47 0 $self->zilla->prune_file($file);
48 }
49  
50 0 return;
51 }
52  
53 0 ▶sub munge_files {
Subroutine munge_files: not called CC=3 SCAR=24.8
Pod undocumented
54 0 my ($self) = @_;
55  
56 0 my $source_dir = $self->source_dir;
57  
58 0 for my $file ( @{ $self->found_files } ) {
59 0 my $pod_file = file($source_dir, $file->name);
60 0 ▶ next unless -e $pod_file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $pod_file 0 0 0
61 0 $self->munge_file($file, $pod_file);
62 }
63 }
64  
65 0 ▶sub munge_file {
Subroutine munge_file: not called CC=1 SCAR=6.9
Pod undocumented
66 0 my ($self, $file, $pod_file) = @_;
67 0 $self->log_debug(
68 [ 'appending Pod from %s to %s', $pod_file->stringify, $file->name ]
69 );
70 0 $file->content($file->content . "\n" . $pod_file->slurp);
71 }
72  
73 1 __PACKAGE__->meta->make_immutable;
74 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 1 1;
76  
77  
78  
79 =pod
80  
81 =head1 NAME
82  
83 Dist::Zilla::Plugin::AppendExternalData - Append data to gathered files
84  
85 =head1 VERSION
86  
87 version 0.003
88  
89 =head1 SYNOPSIS
90  
91 [AppendExternalData]
92 source_dir = pod ; required
93 prune_source_dir = 1 ; default
94  
95 =head1 DESCRIPTION
96  
97 This L<Dist::Zilla> plugin appends files in a directory to files being
98 gathered for the distribution.
99  
100 When using this plugin, be thoughtful about the order in which you want
101 files to be modified. For example, if you are appending Pod, it makes
102 a big difference if you append before or after a plugin like
103 C<<< PodWeaver >>>. If you list this plugin first, the Pod will be appended
104 before weaving and the added Pod will wind up in the middle of the generated
105 Pod. If this plugin is listed last, the Pod will be appended after
106 weaving and will follow the generated Pod from C<<< PodWeaver >>>.
107  
108 If appending a C<<< __DATA__ >>> section, be sure to put this plugin last
109 among plugins that modify your files.
110  
111 =head1 ATTRIBUTES
112  
113 =head2 source_dir (REQUIRED)
114  
115 This is the directory containing data to append.
116 Files within this directory that have the same relative names as
117 modules and executables will have their contents appended. E.g.
118 if C<source_dir> is F<pod>, then F<pod/lib/Foo.pm> will be appended
119 to F<lib/Foo.pm>. If a gathered file does not match a file in the
120 source directory or vice-versa, it will not altered and is not
121 considered an error.
122  
123 =head2 prune_source_dir
124  
125 This is a boolean that indicates whether the C<source_dir> should also be
126 pruned from the distribution. The default is 1.
127  
128 =for Pod::Coverage prune_files munge_files munge_file
129  
130 =head1 CAVEAT
131  
132 This is a proof-of-concept and does not yet have any tests of its behavior.
133  
134 =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders
135  
136 =head1 SUPPORT
137  
138 =head2 Bugs / Feature Requests
139  
140 Please report any bugs or feature requests through the issue tracker
141 at L<http://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Plugin-AppendExternalData>.
142 You will be notified automatically of any progress on your issue.
143  
144 =head2 Source Code
145  
146 This is open source software. The code repository is available for
147 public review and contribution under the terms of the license.
148  
149 L<https://github.com/dagolden/dist-zilla-plugin-appendexternaldata>
150  
151 git clone https://github.com/dagolden/dist-zilla-plugin-appendexternaldata.git
152  
153 =head1 AUTHOR
154  
155 David Golden <dagolden@cpan.org>
156  
157 =head1 COPYRIGHT AND LICENSE
158  
159 This software is Copyright (c) 2012 by David Golden.
160  
161 This is free software, licensed under:
162  
163 The Apache License, Version 2.0, January 2004
164  
165 =cut
166  
167  
168 __END__
↑ Summary