File Coverage

blib/lib/Dist/Zilla/Plugin/Test/EOL.pm
Criterion Covered Total %
statement 42 42 100.0
branch n/a
condition 1 3 33.3
subroutine 12 12 100.0
pod 0 4 0.0
total 55 61 90.1


line stmt bran cond sub pod time code
1 4     4   4259265 use strict;
  4         8  
  4         160  
2 4     4   18 use warnings;
  4         7  
  4         219  
3             package Dist::Zilla::Plugin::Test::EOL; # git description: 0.16-12-g77240fb
4             # ABSTRACT: Author tests making sure correct line endings are used
5             # KEYWORDS: plugin test testing author development whitespace newline linefeed formatting
6             $Dist::Zilla::Plugin::Test::EOL::VERSION = '0.17';
7 4     4   20 use Moose;
  4         5  
  4         29  
8 4     4   22784 use Path::Tiny;
  4         9  
  4         230  
9 4     4   2367 use Sub::Exporter::ForMethods 'method_installer';
  4         2479  
  4         23  
10             use Data::Section 0.004 # fixed header_re
11 4     4   763 { installer => method_installer }, '-setup';
  4         84  
  4         19  
12 4     4   2365 use Moose::Util::TypeConstraints 'role_type';
  4         8  
  4         44  
13 4     4   1440 use namespace::autoclean;
  4         7  
  4         38  
14              
15             with
16             'Dist::Zilla::Role::FileGatherer',
17             'Dist::Zilla::Role::FileMunger',
18             'Dist::Zilla::Role::TextTemplate',
19             'Dist::Zilla::Role::FileFinderUser' => {
20             method => 'found_files',
21             finder_arg_names => [ 'finder' ],
22             default_finders => [ ':InstallModules', ':ExecFiles', ':TestFiles' ],
23             },
24             'Dist::Zilla::Role::PrereqSource',
25             ;
26              
27             has trailing_whitespace => (
28             is => 'ro',
29             isa => 'Bool',
30             default => 1,
31             );
32              
33             has filename => (
34             is => 'ro', isa => 'Str',
35             lazy => 1,
36             default => sub { return 'xt/author/eol.t' },
37             );
38              
39             has files => (
40             isa => 'ArrayRef[Str]',
41             traits => ['Array'],
42             handles => { files => 'elements' },
43             lazy => 1,
44             default => sub { [] },
45             );
46              
47             has _file_obj => (
48             is => 'rw', isa => role_type('Dist::Zilla::Role::File'),
49             );
50              
51             sub mvp_multivalue_args { 'files' }
52 4     4 0 690 sub mvp_aliases { return { file => 'files' } }
53              
54             around dump_config => sub
55             {
56             my ($orig, $self) = @_;
57             my $config = $self->$orig;
58              
59             $config->{+__PACKAGE__} = {
60             map { $_ => $self->$_ } qw(filename trailing_whitespace finder),
61             };
62             return $config;
63             };
64              
65             sub gather_files
66             {
67 4     4 0 213841 my $self = shift;
68              
69 4         2635 require Dist::Zilla::File::InMemory;
70              
71 4         30 $self->add_file(
72             $self->_file_obj(
73             Dist::Zilla::File::InMemory->new(
74             name => $self->filename,
75 4         282703 content => ${$self->section_data('__TEST__')},
76             )
77             )
78             );
79              
80 4         3069 return;
81             }
82              
83             sub munge_files
84             {
85 4     4 0 5914 my $self = shift;
86              
87 12   33     1396 my @filenames = map { path($_->name)->relative('.')->stringify }
  12         12032  
88 4         25 grep { not ($_->can('is_bytes') and $_->is_bytes) }
89 4         10 @{ $self->found_files };
90 4         713 push @filenames, $self->files;
91              
92 4         27 $self->log_debug('adding file ' . $_) foreach @filenames;
93              
94 4         3833 my $file = $self->_file_obj;
95 4         32 $file->content(
96             $self->fill_in_string(
97             $file->content,
98             {
99             dist => \($self->zilla),
100             plugin => \$self,
101             filenames => [ sort @filenames ],
102             trailing_ws => \$self->trailing_whitespace,
103             },
104             )
105             );
106              
107 4         6801 return;
108             }
109              
110             sub register_prereqs
111             {
112 4     4 0 1358 my $self = shift;
113 4         146 $self->zilla->register_prereqs(
114             {
115             type => 'requires',
116             phase => 'develop',
117             },
118             'Test::More' => '0.88',
119             'Test::EOL' => '0',
120             );
121             }
122              
123             __PACKAGE__->meta->make_immutable;
124             1;
125              
126             #pod =pod
127             #pod
128             #pod =head1 DESCRIPTION
129             #pod
130             #pod Generate an author L<Test::EOL>.
131             #pod
132             #pod This is an extension of L<Dist::Zilla::Plugin::InlineFiles>, providing
133             #pod the file F<xt/author/eol.t>, a standard L<Test::EOL> test.
134             #pod
135             #pod =head1 CONFIGURATION OPTIONS
136             #pod
137             #pod This plugin accepts the following options:
138             #pod
139             #pod =head2 C<trailing_whitespace>
140             #pod
141             #pod If this option is set to a true value,
142             #pod C<< { trailing_whitespace => 1 } >> will be passed to
143             #pod L<Test::EOL/all_perl_files_ok>. It defaults to C<1>.
144             #pod
145             #pod What this option is going to do is test for the lack of trailing whitespace at
146             #pod the end of the lines (also known as "trailing space").
147             #pod
148             #pod =head2 C<finder>
149             #pod
150             #pod =for stopwords FileFinder
151             #pod
152             #pod This is the name of a L<FileFinder|Dist::Zilla::Role::FileFinder> for finding
153             #pod files to check. The default value is C<:InstallModules>,
154             #pod C<:ExecFiles> (see also L<Dist::Zilla::Plugin::ExecDir>) and C<:TestFiles>;
155             #pod this option can be used more than once.
156             #pod
157             #pod Other predefined finders are listed in
158             #pod L<Dist::Zilla::Role::FileFinderUser/default_finders>.
159             #pod You can define your own with the
160             #pod L<[FileFinder::ByName]|Dist::Zilla::Plugin::FileFinder::ByName> plugin.
161             #pod
162             #pod =head2 C<file>
163             #pod
164             #pod a filename to also test, in addition to any files found
165             #pod earlier. This option can be repeated to specify multiple additional files.
166             #pod
167             #pod =head2 C<filename>
168             #pod
169             #pod The filename of the test to add - defaults to F<xt/author/test-eol.t>.
170             #pod
171             #pod =for Pod::Coverage mvp_multivalue_args mvp_aliases gather_files munge_files register_prereqs
172             #pod
173             #pod =head1 ACKNOWLEDGMENTS
174             #pod
175             #pod This module is a fork of L<Dist::Zilla::Plugin::EOLTests> and was originally
176             #pod written by Florian Ragwitz. It was forked because the Test:: namespace
177             #pod is preferred for test modules, and because I would prefer to have EOL tests
178             #pod be Author tests.
179             #pod
180             #pod =head1 SEE ALSO
181             #pod
182             #pod =for :list
183             #pod * Test::EOL
184             #pod
185             #pod =cut
186              
187             =pod
188              
189             =encoding UTF-8
190              
191             =head1 NAME
192              
193             Dist::Zilla::Plugin::Test::EOL - Author tests making sure correct line endings are used
194              
195             =head1 VERSION
196              
197             version 0.17
198              
199             =head1 DESCRIPTION
200              
201             Generate an author L<Test::EOL>.
202              
203             This is an extension of L<Dist::Zilla::Plugin::InlineFiles>, providing
204             the file F<xt/author/eol.t>, a standard L<Test::EOL> test.
205              
206             =head1 CONFIGURATION OPTIONS
207              
208             This plugin accepts the following options:
209              
210             =head2 C<trailing_whitespace>
211              
212             If this option is set to a true value,
213             C<< { trailing_whitespace => 1 } >> will be passed to
214             L<Test::EOL/all_perl_files_ok>. It defaults to C<1>.
215              
216             What this option is going to do is test for the lack of trailing whitespace at
217             the end of the lines (also known as "trailing space").
218              
219             =head2 C<finder>
220              
221             =for stopwords FileFinder
222              
223             This is the name of a L<FileFinder|Dist::Zilla::Role::FileFinder> for finding
224             files to check. The default value is C<:InstallModules>,
225             C<:ExecFiles> (see also L<Dist::Zilla::Plugin::ExecDir>) and C<:TestFiles>;
226             this option can be used more than once.
227              
228             Other predefined finders are listed in
229             L<Dist::Zilla::Role::FileFinderUser/default_finders>.
230             You can define your own with the
231             L<[FileFinder::ByName]|Dist::Zilla::Plugin::FileFinder::ByName> plugin.
232              
233             =head2 C<file>
234              
235             a filename to also test, in addition to any files found
236             earlier. This option can be repeated to specify multiple additional files.
237              
238             =head2 C<filename>
239              
240             The filename of the test to add - defaults to F<xt/author/test-eol.t>.
241              
242             =for Pod::Coverage mvp_multivalue_args mvp_aliases gather_files munge_files register_prereqs
243              
244             =head1 ACKNOWLEDGMENTS
245              
246             This module is a fork of L<Dist::Zilla::Plugin::EOLTests> and was originally
247             written by Florian Ragwitz. It was forked because the Test:: namespace
248             is preferred for test modules, and because I would prefer to have EOL tests
249             be Author tests.
250              
251             =head1 SEE ALSO
252              
253             =over 4
254              
255             =item *
256              
257             Test::EOL
258              
259             =back
260              
261             =head1 AUTHORS
262              
263             =over 4
264              
265             =item *
266              
267             Florian Ragwitz <rafl@debian.org>
268              
269             =item *
270              
271             Caleb Cushing <xenoterracide@gmail.com>
272              
273             =item *
274              
275             Karen Etheridge <ether@cpan.org>
276              
277             =back
278              
279             =head1 COPYRIGHT AND LICENSE
280              
281             This software is copyright (c) 2010 by Florian Ragwitz <rafl@debian.org>.
282              
283             This is free software; you can redistribute it and/or modify it under
284             the same terms as the Perl 5 programming language system itself.
285              
286             =head1 CONTRIBUTORS
287              
288             =for stopwords Olivier Mengué Shlomi Fish
289              
290             =over 4
291              
292             =item *
293              
294             Olivier Mengué <dolmen@cpan.org>
295              
296             =item *
297              
298             Shlomi Fish <shlomif@shlomifish.org>
299              
300             =back
301              
302             =cut
303              
304             __DATA__
305             ___[ __TEST__ ]___
306             use strict;
307             use warnings;
308              
309             # this test was generated with {{ ref($plugin) . ' ' . ($plugin->VERSION || '<self>') }}
310              
311             use Test::More 0.88;
312             use Test::EOL;
313              
314             my @files = (
315             {{ join(",\n", map { " '" . $_ . "'" } map { s/'/\\'/g; $_ } @filenames) }}
316             );
317              
318             eol_unix_ok($_, { trailing_whitespace => {{ $trailing_ws }} }) foreach @files;
319             done_testing;