Test/Perl/Critic.pm

filter: Statementstmt 95.4% 83 / 87 Branchbran 71.4% 10 / 14 Conditioncond 100% 5 / 5 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 21 / 21 Podpod 0.0% 0 / 4 totaltotal 91.0% 122 / 134 CC 10 SCAR 11.3
CC
10
Cov
92%
munge_file
8.3
__ANON__
4.0
BEGIN
1.0
CRAP 3.1
↑ Summary CriticTests.pm »
1 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Dist::Zilla::Plugin::Test::Perl::Critic; # git description: v3.004-4-gbd33dcc
6 # ABSTRACT: Tests to check your code against best practices
7 1 our $VERSION = '3.005';
8 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Moose::Util::TypeConstraints qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
11 role_type
12 1 );
13 1 ▶use Dist::Zilla::File::InMemory;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Sub::Exporter::ForMethods 'method_installer';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Data::Section 0.004 { installer => method_installer }, '-setup';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Data::Dumper ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # and when the time comes, treat them like templates
21 1 with (
22 'Dist::Zilla::Role::FileFinderUser' => {
23 default_finders => [],
24 },
25 'Dist::Zilla::Role::FileGatherer',
26 'Dist::Zilla::Role::FileMunger',
27 'Dist::Zilla::Role::TextTemplate',
28 'Dist::Zilla::Role::PrereqSource',
29 );
30  
31 1 has filename => (
32 is => 'ro',
33 default => 'xt/author/critic.t',
34 );
35  
36 has _file => (
37 is => 'ro',
38 isa => role_type('Dist::Zilla::Role::File'),
39 lazy => 1,
40 6 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
41 6 my $self = shift;
42 return Dist::Zilla::File::InMemory->new(
43 name => $self->filename,
44 6 content => ${$self->section_data('test-perl-critic')},
45 );
46 },
47 1 );
48  
49 6 ▶sub mvp_aliases { {
Subroutine mvp_aliases: called CC=1 SCAR=0.0
Pod undocumented
50 6 profile => 'critic_config',
51 } }
52  
53 6 ▶sub mvp_multivalue_args { qw(
Subroutine mvp_multivalue_args: called CC=1 SCAR=0.0
54 files
55 ) }
56  
57 1 has critic_config => (
58 is => 'ro',
59 isa => 'Str',
60 );
61  
62 has embed_critic_config => (
63 is => 'ro',
64 isa => 'Bool',
65 6 ▶ default => sub { 0; },
Subroutine __ANON__: called CC=1 SCAR=0.0
66 1 );
67  
68 1 has verbose => (
69 is => 'ro',
70 );
71  
72 1 has files => (
73 is => 'ro',
74 isa => 'ArrayRef[Str]',
75 );
76  
77 has all_files => (
78 is => 'ro',
79 lazy => 1,
80 isa => 'Maybe[ArrayRef[Str]]',
81 6 ▶ default => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
82 6 my $self = shift;
83 6 my $files = $self->files;
84 return undef
85 6 ▶ if !@{ $self->finder } && !$files;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->finder;} or $files 4 2 6
Condition100%3/3
@{$self->finder;} or $files
l!l&&r!l&&!r
114
MC/DC100%2/2
@{$self->finder;} or $files
@{$self->finder;} $files
Truth table100%3/3
A or B
A= @{$self->finder;}B= $files
ABresult
1X1
011
000
86 return [
87 2 ▶ @{ $files || [] },
Condition100%2/2
$files || []
l!l
11
MC/DC100%1/1
$files || []
$files
Truth table100%2/2
A
A= $files
Aresult
11
00
88 2 (map $_->name, @{ $self->found_files }),
89 ];
90 },
91 1 );
92  
93 6 ▶sub gather_files {
Subroutine gather_files: called CC=1 SCAR=0.0
Pod undocumented
94 6 my $self = shift;
95 6 $self->add_file( $self->_file );
96 }
97  
98 6 ▶sub register_prereqs {
Subroutine register_prereqs: called CC=1 SCAR=0.0
Pod undocumented
99 6 my $self = shift;
100  
101 6 $self->zilla->register_prereqs(
102 {
103 type => 'requires',
104 phase => 'develop',
105 },
106 'Test::Perl::Critic' => 0,
107  
108 # TODO also extract list of policies used in file $self->critic_config
109 );
110 }
111  
112 6 ▶sub _dumper {
Subroutine _dumper: called CC=1 SCAR=0.0
113 6 my ($value) = @_;
114 6 local $Data::Dumper::Indent = 1;
115 6 local $Data::Dumper::Useqq = 1;
116 6 local $Data::Dumper::Terse = 1;
117 6 local $Data::Dumper::Sortkeys = 1;
118 6 local $Data::Dumper::Trailingcomma = 1;
119 6 my $dump = Data::Dumper::Dumper($value);
120 6 $dump =~ s{\n\z}{};
121 6 return $dump;
122 }
123  
124 17 ▶sub munge_file {
Subroutine munge_file: called CC=7 SCAR=21.1
Pod undocumented
125 17 my $self = shift;
126 17 my ($file) = @_;
127  
128 return
129 17 ▶ unless $file == $self->_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file == $self->_file 11 6 17
130  
131 6 my $options = {};
132 6 my @conf;
133 6 ▶ if (defined(my $verbose = $self->verbose)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $verbose = $self->verbose)) 0 6 6
134 0 $options->{'-verbose'} = $verbose;
135 }
136 6 ▶ if ($self->embed_critic_config) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->embed_critic_config) { } 0 6 6
elsif (my $profile = $self->critic_config) { } 1 5 6
elsif (grep(($_->name eq 'perlcritic.rc'), @{$self->zilla->files;})) { } 3 2 5
137 0 ▶ if (my $profile = $self->critic_config) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $profile = $self->critic_config) { } 0 0 0
138 0 @conf = path($profile)->lines_utf8( { chomp => 1, });
139 }
140 else {
141 0 @conf = path('.perlcriticrc')->lines_utf8( { chomp => 1, });
142 }
143 }
144 elsif (my $profile = $self->critic_config) {
145 1 $options->{'-profile'} = $profile;
146 }
147 5 elsif (grep $_->name eq 'perlcritic.rc', @{ $self->zilla->files }) {
148 3 $options->{'-profile'} = 'perlcritic.rc';
149 }
150  
151 $file->content(
152 6 $self->fill_in_string(
153 $file->content,
154 {
155 dist => \($self->zilla),
156 plugin => \$self,
157 dumper => \\&_dumper,
158 options => \$options,
159 files => \$self->all_files,
160 conf => \\@conf,
161 embed_critic_config => 0 + $self->embed_critic_config,
162 }
163 )
164 );
165 }
166  
167 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
168 1 __PACKAGE__->meta->make_immutable;
169 1 1;
170 #pod =pod
171 #pod
172 #pod =for Pod::Coverage gather_files register_prereqs munge_file mvp_aliases
173 #pod
174 #pod =for stopwords LICENCE
175 #pod
176 #pod =head1 SYNOPSIS
177 #pod
178 #pod In your F<dist.ini>:
179 #pod
180 #pod [Test::Perl::Critic]
181 #pod critic_config = perlcritic.rc ; default / relative to project root
182 #pod
183 #pod =head1 DESCRIPTION
184 #pod
185 #pod This will provide a F<xt/author/critic.t> file for use during the "test" and
186 #pod "release" calls of C<dzil>. To use this, make the changes to F<dist.ini>
187 #pod above and run one of the following:
188 #pod
189 #pod dzil test
190 #pod dzil release
191 #pod
192 #pod During these runs, F<xt/author/critic.t> will use L<Test::Perl::Critic> to run
193 #pod L<Perl::Critic> against your code and by report findings.
194 #pod
195 #pod =head1 OPTIONS
196 #pod
197 #pod =head2 filename
198 #pod
199 #pod The file name of the test to generate. Defaults to F<xt/author/critic.t>.
200 #pod
201 #pod =head2 critic_config
202 #pod
203 #pod This plugin accepts the C<critic_config> option, which s
204 #pod Specifies your own config file for L<Perl::Critic>. It defaults to
205 #pod C<perlcritic.rc>, relative to the project root. If the file does not exist,
206 #pod L<Perl::Critic> will use its defaults.
207 #pod
208 #pod The option can also be configured using the C<profile> alias.
209 #pod
210 #pod =head2 verbose
211 #pod
212 #pod If configured, overrides the C<-verbose> option to L<Perl::Critic>.
213 #pod
214 #pod =head2 files
215 #pod
216 #pod If specified, will be used as the list of files to check. If neither C<files>
217 #pod C<finder> is specified, L<Test::Perl::Critic>'s default behavior of checking
218 #pod all files will be used.
219 #pod
220 #pod =head2 finder
221 #pod
222 #pod Can be specified to use a L<file finder|Dist::Zilla::Role::FileFinderUser/default_finders>
223 #pod to select the files to check, rather than checking all files.
224 #pod
225 #pod =cut
226  
227 =pod
228  
229 =encoding UTF-8
230  
231 =head1 NAME
232  
233 Dist::Zilla::Plugin::Test::Perl::Critic - Tests to check your code against best practices
234  
235 =head1 VERSION
236  
237 version 3.005
238  
239 =head1 SYNOPSIS
240  
241 In your F<dist.ini>:
242  
243 [Test::Perl::Critic]
244 critic_config = perlcritic.rc ; default / relative to project root
245  
246 =head1 DESCRIPTION
247  
248 This will provide a F<xt/author/critic.t> file for use during the "test" and
249 "release" calls of C<dzil>. To use this, make the changes to F<dist.ini>
250 above and run one of the following:
251  
252 dzil test
253 dzil release
254  
255 During these runs, F<xt/author/critic.t> will use L<Test::Perl::Critic> to run
256 L<Perl::Critic> against your code and by report findings.
257  
258 =for Pod::Coverage gather_files register_prereqs munge_file mvp_aliases
259  
260 =for stopwords LICENCE
261  
262 =head1 OPTIONS
263  
264 =head2 filename
265  
266 The file name of the test to generate. Defaults to F<xt/author/critic.t>.
267  
268 =head2 critic_config
269  
270 This plugin accepts the C<critic_config> option, which s
271 Specifies your own config file for L<Perl::Critic>. It defaults to
272 C<perlcritic.rc>, relative to the project root. If the file does not exist,
273 L<Perl::Critic> will use its defaults.
274  
275 The option can also be configured using the C<profile> alias.
276  
277 =head2 verbose
278  
279 If configured, overrides the C<-verbose> option to L<Perl::Critic>.
280  
281 =head2 files
282  
283 If specified, will be used as the list of files to check. If neither C<files>
284 C<finder> is specified, L<Test::Perl::Critic>'s default behavior of checking
285 all files will be used.
286  
287 =head2 finder
288  
289 Can be specified to use a L<file finder|Dist::Zilla::Role::FileFinderUser/default_finders>
290 to select the files to check, rather than checking all files.
291  
292 =head1 SUPPORT
293  
294 Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Plugin-Test-Perl-Critic>
295 (or L<bug-Dist-Zilla-Plugin-Test-Perl-Critic@rt.cpan.org|mailto:bug-Dist-Zilla-Plugin-Test-Perl-Critic@rt.cpan.org>).
296  
297 There is also an irc channel available for users of this distribution, at
298 L<C<#distzilla> on C<irc.perl.org>|irc://irc.perl.org/#distzilla>.
299  
300 =head1 AUTHOR
301  
302 Jerome Quelin
303  
304 =head1 CONTRIBUTORS
305  
306 =for stopwords Karen Etheridge Jérôme Quelin Graham Knop Kent Fredric Olivier Mengué Gryphon Shafer Mikko Koivunalho Stephen R. Scaffidi Alexander Hartmaier Mike Doherty
307  
308 =over 4
309  
310 =item *
311  
312 Karen Etheridge <ether@cpan.org>
313  
314 =item *
315  
316 Jérôme Quelin <jquelin@gmail.com>
317  
318 =item *
319  
320 Graham Knop <haarg@haarg.org>
321  
322 =item *
323  
324 Kent Fredric <kentfredric@gmail.com>
325  
326 =item *
327  
328 Olivier Mengué <dolmen@cpan.org>
329  
330 =item *
331  
332 Gryphon Shafer <gryphon@goldenguru.com>
333  
334 =item *
335  
336 Mikko Koivunalho <mikkoi@cpan.org>
337  
338 =item *
339  
340 Stephen R. Scaffidi <stephen@scaffidi.net>
341  
342 =item *
343  
344 Alexander Hartmaier <abraxxa@cpan.org>
345  
346 =item *
347  
348 Mike Doherty <doherty@cs.dal.ca>
349  
350 =back
351  
352 =head1 COPYRIGHT AND LICENCE
353  
354 This software is copyright (c) 2009 by Jerome Quelin.
355  
356 This is free software; you can redistribute it and/or modify it under
357 the same terms as the Perl 5 programming language system itself.
358  
359 =cut
360  
361 __DATA__
↑ Summary CriticTests.pm »