File Coverage

blib/lib/Test/Apocalypse/PerlCritic.pm
Criterion Covered Total %
statement 17 19 89.4
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 24 26 92.3


line stmt bran cond sub pod time code
1             #
2             # This file is part of Test-Apocalypse
3             #
4             # This software is copyright (c) 2014 by Apocalypse.
5             #
6             # This is free software; you can redistribute it and/or modify it under
7             # the same terms as the Perl 5 programming language system itself.
8             #
9 38     38   8744540 use strict; use warnings;
  38     38   87  
  38         1221  
  38         159  
  38         76  
  38         1681  
10             package Test::Apocalypse::PerlCritic;
11             $Test::Apocalypse::PerlCritic::VERSION = '1.006';
12             BEGIN {
13 38     38   502 $Test::Apocalypse::PerlCritic::AUTHORITY = 'cpan:APOCAL';
14             }
15              
16             # ABSTRACT: Plugin for Test::Perl::Critic
17              
18 38     38   190 use Test::More;
  38         42  
  38         255  
19 38     38   27163 use Test::Perl::Critic 1.02;
  38         44308963  
  38         190  
20 38     38   2320 use File::Spec 3.31;
  38         609  
  38         266  
21              
22             # This is so we always have all PerlCritic plugins installed, yay!
23 38     38   7570 use Task::Perl::Critic 1.007;
  0            
  0            
24             use Perl::Critic::Itch 0.07; # for CodeLayout::ProhibitHashBarewords
25             use Perl::Critic::Deprecated 1.108;
26              
27             sub _do_automated { 0 }
28              
29             sub do_test {
30             # set default opts
31             require Perl::Critic::Utils::Constants;
32             my %opts = (
33             '-verbose' => "[%p] %m at line %l, near '%r'\n",
34             '-severity' => 'brutal',
35             '-profile-strictness' => $Perl::Critic::Utils::Constants::PROFILE_STRICTNESS_FATAL,
36             );
37              
38             # Do we have a perlcriticrc?
39             my $rcfile = File::Spec->catfile( 't', 'perlcriticrc' );
40             my $default_rcfile; # did we generate a default?
41             if ( ! -e $rcfile ) {
42             # Maybe it's in the CWD?
43             if ( ! -e 'perlcriticrc' ) {
44             # Generate it using the default!
45             if ( ! -d 't' ) {
46             # We're already in the test dir
47             $rcfile = 'perlcriticrc';
48             }
49              
50             open( my $rc, '>', $rcfile ) or die "Unable to open $rcfile for writing: $!";
51             print $rc _default_perlcriticrc();
52             close $rc or die "Unable to close $rcfile: $!";
53             $default_rcfile = 1;
54             } else {
55             $rcfile = 'perlcriticrc';
56             }
57             }
58             Test::Perl::Critic->import( %opts, '-profile' => $rcfile );
59              
60             TODO: {
61             local $TODO = "PerlCritic";
62             all_critic_ok();
63             }
64              
65             if ( $default_rcfile ) {
66             unlink $rcfile or die "Unable to remove $rcfile: $!";
67             }
68              
69             return;
70             }
71              
72             sub _default_perlcriticrc {
73             # Build a default file
74             my $rcfile = <<'EOF';
75             # If you're wondering why there's a gazillion exclusions in here...
76             # It's because I installed every Perl::Critic policy there is ;)
77              
78             # ---------------------------------------------
79             # Policies that is already covered by other tests in Test::Apocalypse
80             # ---------------------------------------------
81              
82             [-Compatibility::PerlMinimumVersionAndWhy]
83             [-Modules::RequirePerlVersion]
84             # covered by MinimumVersion
85              
86             [-Documentation::PodSpelling]
87             # covered by Pod_Spelling
88              
89             # ---------------------------------------------
90             # editor/style stuff that is too strict
91             # ---------------------------------------------
92              
93             [-Bangs::ProhibitCommentedOutCode]
94             [-Bangs::ProhibitFlagComments]
95             [-Bangs::ProhibitVagueNames]
96             [-CodeLayout::ProhibitHardTabs]
97             [-CodeLayout::ProhibitParensWithBuiltins]
98             [-CodeLayout::RequireTidyCode]
99             [-CodeLayout::RequireTrailingCommaAtNewline]
100             [-CodeLayout::RequireUseUTF8]
101             [-Documentation::RequirePodLinksIncludeText]
102             [-Documentation::RequirePODUseEncodingUTF8]
103             [-Documentation::ProhibitUnbalancedParens]
104             [-Editor::RequireEmacsFileVariables]
105             [-Miscellanea::RequireRcsKeywords]
106             [-Modules::ProhibitExcessMainComplexity]
107             [-NamingConventions::Capitalization]
108             [-NamingConventions::ProhibitMixedCaseVars]
109             [-Subroutines::ProhibitExcessComplexity]
110             [-Subroutines::ProhibitSubroutinePrototypes]
111             [-Tics::ProhibitLongLines]
112             [-ValuesAndExpressions::ProhibitEscapedCharacters]
113             [-ValuesAndExpressions::ProhibitLongChainsOfMethodCalls]
114             [-ValuesAndExpressions::ProhibitMagicNumbers]
115             [-ValuesAndExpressions::ProhibitNoisyQuotes]
116             [-ValuesAndExpressions::RestrictLongStrings]
117              
118             # ---------------------------------------------
119             # miscellaneous policies that is just plain annoying
120             # ---------------------------------------------
121              
122             [-BuiltinFunctions::ProhibitStringyEval]
123             [-BuiltinFunctions::ProhibitStringySplit]
124             [-BuiltinFunctions::ProhibitUselessTopic]
125             [-Compatibility::ProhibitThreeArgumentOpen]
126             [-ControlStructures::ProhibitCascadingIfElse]
127             [-ControlStructures::ProhibitDeepNests]
128             [-ControlStructures::ProhibitPostfixControls]
129             [-ErrorHandling::RequireCarping]
130             [-ErrorHandling::RequireCheckingReturnValueOfEval]
131             [-ErrorHandling::RequireUseOfExceptions]
132             [-InputOutput::RequireBracedFileHandleWithPrint]
133             [-InputOutput::RequireBriefOpen]
134             [-InputOutput::RequireCheckedSyscalls]
135             [-Lax::ProhibitEmptyQuotes::ExceptAsFallback]
136             [-Lax::ProhibitStringyEval::ExceptForRequire]
137             [-Miscellanea::ProhibitTies]
138             [-Modules::ProhibitAutomaticExportation]
139             [-Modules::RequireBarewordIncludes]
140             [-Modules::RequireExplicitPackage]
141             [-NamingConventions::ProhibitMixedCaseSubs]
142             [-References::ProhibitDoubleSigils]
143             [-RegularExpressions::ProhibitEscapedMetacharacters]
144             [-RegularExpressions::ProhibitFixedStringMatches]
145             [-RegularExpressions::RequireDotMatchAnything]
146             [-RegularExpressions::RequireExtendedFormatting]
147             [-RegularExpressions::RequireLineBoundaryMatching]
148             [-RegularExpressions::ProhibitUselessTopic]
149             [-Subroutines::ProhibitCallsToUndeclaredSubs]
150             [-Subroutines::ProhibitCallsToUnexportedSubs]
151             [-Subroutines::ProhibitManyArgs]
152             [-Subroutines::ProhibitUnusedPrivateSubroutines]
153             [-Subroutines::ProtectPrivateSubs]
154             [-Subroutines::RequireArgUnpacking]
155             [-Subroutines::RequireFinalReturn]
156             [-TestingAndDebugging::ProhibitNoStrict]
157             [-TestingAndDebugging::ProhibitNoWarnings]
158             [-ValuesAndExpressions::ProhibitAccessOfPrivateData]
159             [-ValuesAndExpressions::ProhibitCommaSeparatedStatements]
160             [-ValuesAndExpressions::ProhibitEmptyQuotes]
161             [-ValuesAndExpressions::ProhibitFiletest_f]
162             [-ValuesAndExpressions::ProhibitInterpolationOfLiterals]
163             [-ValuesAndExpressions::RequireInterpolationOfMetachars]
164             [-Variables::ProhibitLocalVars]
165             [-Variables::ProhibitPunctuationVars]
166             [-Variables::ProhibitPackageVars]
167             [-Variables::RequireInitializationForLocalVars]
168              
169             EOF
170              
171             # Ignore optional stuff?
172             unless ( exists $ENV{'PERL_CRITIC_STRICT'} and $ENV{'PERL_CRITIC_STRICT'} ) {
173             $rcfile .= <<'EOF';
174             # ---------------------------------------------
175             # TODO probably sane policies but need to do a lot of work to fix them...
176             # ---------------------------------------------
177              
178             [-CodeLayout::ProhibitHashBarewords]
179             # sometimes we're lazy!
180              
181             [-Compatibility::PodMinimumVersion]
182             # there should be a Test::Apocalypse check for that!
183              
184             [-ControlStructures::ProhibitUnlessBlocks]
185             # it's so easy to be lazy!
186              
187             [-Documentation::RequirePodSections]
188             # what is the "default" list? Obviously not PBP because it requires way too much sections!
189              
190             [-Miscellanea::ProhibitUselessNoCritic]
191             # I don't want to go through my old code and clean them up... laziness again!
192              
193             [-Modules::RequireExplicitInclusion]
194             # while this makes sense sometimes it's a drag to list the modules that you *know* a prereq will pull in...
195              
196             [-RegularExpressions::ProhibitComplexRegexes]
197             # while this is true it's unavoidable in some cases...
198              
199             [-RegularExpressions::ProhibitUnusualDelimiters]
200             # sometimes we like other delims...
201              
202             [-Subroutines::ProhibitBuiltinHomonyms]
203             # in POE "shutdown" is commonly used, also in some classes we define convenience methods like "print" and etc...
204              
205             [-ValuesAndExpressions::ProhibitMixedBooleanOperators]
206             # sometimes it feels "natural" to code in that style...
207              
208             [-ValuesAndExpressions::ProhibitVersionStrings]
209             # is this really a problem? If so, it's still a lot of work to go through code and figure out the proper string...
210              
211             [-ValuesAndExpressions::RequireConstantOnLeftSideOfEquality]
212             # I think "$^O eq 'MSWin32'" is valid... I don't want to rewrite tons of code just to satisfy this...
213              
214             EOF
215             }
216              
217             return $rcfile;
218             }
219              
220             1;
221              
222             __END__
223              
224             =pod
225              
226             =encoding UTF-8
227              
228             =for :stopwords Apocalypse Niebur Ryan
229              
230             =for Pod::Coverage do_test
231              
232             =head1 NAME
233              
234             Test::Apocalypse::PerlCritic - Plugin for Test::Perl::Critic
235              
236             =head1 VERSION
237              
238             This document describes v1.006 of Test::Apocalypse::PerlCritic - released October 25, 2014 as part of Test-Apocalypse.
239              
240             =head1 DESCRIPTION
241              
242             Encapsulates L<Test::Perl::Critic> functionality.
243              
244             Automatically sets the following options:
245              
246             -verbose => 8,
247             -severity => 'brutal',
248             -profile => 't/perlcriticrc',
249             -profile-strictness => 'fatal',
250              
251             If the C<t/perlcriticrc> file isn't present a default one will be generated and used. Please see the source of this module
252             for the default config, it is too lengthy to copy and paste into this POD! If you want to override the critic options,
253             please create your own C<t/perlcriticrc> file in the distribution!
254              
255             If you want to ignore the "optional" exclusions in the default perlcriticrc, just set C<$ENV{PERL_CRITIC_STRICT}> to a true value.
256              
257             =head1 SEE ALSO
258              
259             Please see those modules/websites for more information related to this module.
260              
261             =over 4
262              
263             =item *
264              
265             L<Test::Apocalypse|Test::Apocalypse>
266              
267             =item *
268              
269             L<Perl::Critic|Perl::Critic>
270              
271             =back
272              
273             =head1 AUTHOR
274              
275             Apocalypse <APOCAL@cpan.org>
276              
277             =head1 COPYRIGHT AND LICENSE
278              
279             This software is copyright (c) 2014 by Apocalypse.
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             The full text of the license can be found in the
285             F<LICENSE> file included with this distribution.
286              
287             =head1 DISCLAIMER OF WARRANTY
288              
289             THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
290             APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
291             HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
292             OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
293             THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
294             PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
295             IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
296             ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
297              
298             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
299             WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
300             THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
301             GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
302             USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
303             DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
304             PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
305             EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
306             SUCH DAMAGES.
307              
308             =cut