Test/NoTabs.pm

filter: Statementstmt 100% 64 / 64 Branchbran 58.3% 7 / 12 Conditioncond 55.5% 5 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 4 totaltotal 84.5% 93 / 110 CC 11 SCAR 15.3
CC
11
Cov
89%
__ANON__
10.4
munge_files
3.0
BEGIN
1.0
CRAP 4.6
↑ Summary NoTabsTests.pm »
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 5 our $VERSION = '0.15';
7  
8 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Sub::Exporter::ForMethods 'method_installer'; # method_installer returns a sub.
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Data::Section 0.004 # fixed header_re
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 { installer => method_installer }, '-setup';
13 5 ▶use Moose::Util::TypeConstraints 'role_type';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 5 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 4 ▶ default => sub { return 'xt/author/no-tabs.t' },
Subroutine __ANON__: called CC=1 SCAR=0.0
31 5 );
32  
33 has files => (
34 isa => 'ArrayRef[Str]',
35 traits => ['Array'],
36 handles => { files => 'elements' },
37 lazy => 1,
38 4 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
39 5 );
40  
41 5 has _file_obj => (
42 is => 'rw', isa => role_type('Dist::Zilla::Role::File'),
43 );
44  
45 5 ▶sub mvp_multivalue_args { qw(files module_finder script_finder) }
Subroutine mvp_multivalue_args: called CC=1 SCAR=0.0
46 5 ▶sub mvp_aliases { return { file => 'files' } }
Subroutine mvp_aliases: called CC=1 SCAR=0.0
Pod undocumented
47  
48 around BUILDARGS => sub
49 5 ▶{
Subroutine __ANON__: called CC=9 SCAR=23.4
50 5 my $orig = shift;
51 5 my $self = shift;
52 5 my $args = $self->$orig(@_);
53  
54 # handle legacy args
55 5 my $module_finder = delete $args->{module_finder};
56 5 my $script_finder = delete $args->{script_finder};
57 5 ▶ if ($module_finder or $script_finder)
Branch: 1 branch
BranchTrueFalseTotal
if ($module_finder or $script_finder) 1 4 5
Condition66%2/3
$module_finder or $script_finder
l!l&&r!l&&!r
104
MC/DC50%1/2
$module_finder or $script_finder
$module_finder $script_finder
Truth table66%2/3
A or B
A= $module_finderB= $script_finder
ABresult
1X1
011
000
58 {
59 1 $args->{zilla}->log('folding deprecated options (module_finder, script_finder) into finder');
60 1 ▶ $args->{finder} = [ $args->finder ] if $args->{finder} and not ref $args->{finder};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"finder"} and not ref $args->{"finder"} 0 1 1
Condition33%1/3
$args->{"finder"} and not ref $args->{"finder"}
!ll&&!rl&&r
100
MC/DC0%0/2
$args->{"finder"} and not ref $args->{"finder"}
$args->{"finder"} not ref $args->{"finder"}
Truth table33%1/3
A and not(B)
A= $args->{"finder"}B= not ref $args->{"finder"}
ABresult
0X0
100
111
61  
62 1 ▶ push @{$args->{finder}},
Branch: 2 branches
BranchTrueFalseTotal
$module_finder ? : 1 0 1
ref $module_finder ? : 1 0 1
63 $module_finder
64 ? (ref $module_finder ? @$module_finder : $module_finder)
65 : ':InstallModules';
66  
67 1 ▶ push @{$args->{finder}},
Branch: 2 branches
BranchTrueFalseTotal
$script_finder ? : 1 0 1
ref $script_finder ? : 1 0 1
68 $script_finder
69 ? (ref $script_finder ? @$script_finder : $script_finder)
70 : (':ExecFiles', ':TestFiles');
71 }
72  
73 5 return $args;
74 5 };
75  
76 around dump_config => sub
77 2 ▶{
Subroutine __ANON__: called CC=1 SCAR=0.0
78 2 my ($orig, $self) = @_;
79 2 my $config = $self->$orig;
80  
81 2 $config->{+__PACKAGE__} = {
82 finder => $self->finder,
83 filename => $self->filename,
84 };
85 2 return $config;
86 5 };
87  
88 sub register_prereqs
89 5 ▶{
Subroutine register_prereqs: called CC=1 SCAR=0.0
Pod undocumented
90 5 my $self = shift;
91 5 $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 5 ▶{
Subroutine gather_files: called CC=1 SCAR=0.0
Pod undocumented
103 5 my $self = shift;
104  
105 5 require Dist::Zilla::File::InMemory;
106  
107 $self->add_file(
108 $self->_file_obj(
109 Dist::Zilla::File::InMemory->new(
110 name => $self->filename,
111 5 content => ${$self->section_data('__TEST__')},
112 )
113 )
114 );
115 5 return;
116 }
117  
118 sub munge_files
119 5 ▶{
Subroutine munge_files: called CC=3 SCAR=11.0
Pod undocumented
120 5 my $self = shift;
121  
122 11 my @filenames = map { path($_->name)->relative('.')->stringify }
123 12 ▶ grep { not ($_->can('is_bytes') and $_->is_bytes) }
Condition66%2/3
$_->can('is_bytes') && $_->is_bytes
!ll&&!rl&&r
0111
MC/DC50%1/2
$_->can('is_bytes') && $_->is_bytes
$_->can('is_bytes') $_->is_bytes
Truth table66%2/3
A && B
A= $_->can('is_bytes')B= $_->is_bytes
ABresult
0X0
100
111
124 5 @{ $self->found_files };
125 5 push @filenames, $self->files;
126  
127 5 $self->log_debug('adding file ' . $_) foreach @filenames;
128  
129 5 my $file = $self->_file_obj;
130 5 $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 return;
142 }
143  
144 5 __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__
↑ Summary NoTabsTests.pm »