File Coverage

blib/lib/Dist/Zilla/Plugin/Test/NoTabs.pm
Criterion Covered Total %
statement 36 36 100.0
branch n/a
condition 2 3 66.6
subroutine 10 10 100.0
pod 0 4 0.0
total 48 53 90.5


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