File Coverage

inc/Perl/Critic/Module/Build.pm
Criterion Covered Total %
statement 20 83 24.1
branch 0 20 0.0
condition 0 6 0.0
subroutine 7 16 43.7
pod 1 5 20.0
total 28 130 21.5


line stmt bran cond sub pod time code
1             package Perl::Critic::Module::Build;
2              
3 1     1   18 use 5.010001;
  1         3  
4              
5 1     1   8 use strict;
  1         1  
  1         59  
6 1     1   4 use warnings;
  1         1  
  1         95  
7              
8             our $VERSION = '1.126';
9              
10 1     1   15 use Carp;
  1         2  
  1         122  
11 1     1   521 use English qw< $OS_ERROR $EXECUTABLE_NAME -no_match_vars >;
  1         3350  
  1         7  
12 1     1   307 use File::Find;
  1         1  
  1         64  
13              
14              
15 1     1   401 use parent 'Perl::Critic::Module::Build::Standard';
  1         269  
  1         5  
16              
17              
18             sub ACTION_policysummary {
19 0     0 0   my ($self) = @_;
20              
21 0           require Perl::Critic::PolicySummaryGenerator;
22 0           Perl::Critic::PolicySummaryGenerator->import(
23             qw< generate_policy_summary >
24             );
25              
26 0           my $policy_summary_file = generate_policy_summary();
27 0           $self->add_to_cleanup( $policy_summary_file );
28              
29 0           return;
30             }
31              
32              
33             sub ACTION_nytprof {
34 0     0 0   my ($self) = @_;
35              
36 0           $self->depends_on('build');
37 0           $self->_run_nytprof();
38              
39 0           return;
40             }
41              
42              
43             sub ACTION_tags {
44 0     0 0   my ($self) = @_;
45              
46 0           $self->depends_on('build');
47 0           $self->_run_tags();
48              
49 0           return;
50             }
51              
52              
53             sub ACTION_critic {
54 0     0 0   my ($self) = @_;
55              
56 0           $self->depends_on('build');
57 0           $self->_run_critic();
58              
59 0           return;
60             }
61              
62              
63             sub authortest_dependencies {
64 0     0 1   my ($self) = @_;
65              
66 0           $self->depends_on('policysummary');
67 0           $self->SUPER::authortest_dependencies();
68              
69 0           return;
70             }
71              
72              
73             sub _run_nytprof {
74 0     0     my ($self) = @_;
75              
76 0 0         eval { require Devel::NYTProf; 1 }
  0            
  0            
77             or croak 'Devel::NYTProf is required to run nytprof';
78              
79 0 0         eval { require File::Which; File::Which->import('which'); 1 }
  0            
  0            
  0            
80             or croak 'File::Which is required to run nytprof';
81              
82 0 0         my $nytprofhtml = which('nytprofhtml')
83             or croak 'Could not find nytprofhtml in your PATH';
84              
85 0           my $this_perl = $EXECUTABLE_NAME;
86 0           my @perl_args = qw(-Iblib/lib -d:NYTProf blib/script/perlcritic);
87 0           my @perlcritic_args =
88             qw<
89             --noprofile
90             --severity=1
91             --theme=core
92             --exclude=TidyCode
93             --exclude=PodSpelling
94             --exclude=RcsKeywords
95             blib
96             t
97             xt
98             >;
99 0           warn "Running: $this_perl @perl_args @perlcritic_args\n";
100              
101 0           my $status_perlcritic = system $this_perl, @perl_args, @perlcritic_args;
102 0 0         croak "perlcritic failed with status $status_perlcritic"
103             if $status_perlcritic == 1;
104              
105 0           my $status_nytprofhtml = system $nytprofhtml;
106 0 0         croak "nytprofhtml failed with status $status_nytprofhtml"
107             if $status_nytprofhtml;
108              
109 0           return;
110             }
111              
112              
113             sub _run_tags {
114 0     0     my ($self) = @_;
115              
116 0           my $ctags = 'ctags';
117 0           my @ctags_args =
118             qw(
119             -f tags
120             --recurse
121             --totals
122             --exclude=blib
123             --exclude=.git
124             --exclude='*~'
125             --languages=Perl
126             --langmap=Perl:+.t
127             );
128 0           warn "Running: $ctags @ctags_args\n";
129              
130 0           my $status_ctags = system $ctags, @ctags_args;
131 0 0         croak "ctags failed with status $status_ctags"
132             if $status_ctags == 1;
133              
134 0           return;
135             }
136              
137              
138             sub _run_critic {
139 0     0     my ($self) = @_;
140              
141              
142 0           my $perl = $^X;
143 0           my @args =
144             qw(
145             bin/perlcritic
146             -1
147             -q
148             -profile ./perlcriticrc
149             );
150 0           warn "Running: $perl @args\n";
151              
152 0           my @files = @ARGV;
153 0           shift @files;
154              
155 0 0         if ( !@files ) {
156             # There are many bad Perl files in t/ and xt/, so we only want *.t.
157 0           @files = (
158             'bin/perlcritic',
159             );
160             File::Find::find( {
161             wanted => sub {
162 0 0 0 0     if ( -d && /\.git/ ) {
    0 0        
163 0           $File::Find::prune = 1;
164             }
165             elsif ( -f && /\.pm$/ ) {
166 0           push @files, $File::Find::name;
167             }
168 0           return;
169             },
170             },
171 0           'lib'
172             );
173             }
174              
175 0           my $status = system $perl, @args, @files;
176 0 0         croak "perlcritic failed with status $status" if $status;
177              
178 0           return;
179             }
180              
181              
182             1;
183              
184              
185             __END__
186              
187             #-----------------------------------------------------------------------------
188              
189             =pod
190              
191             =for stopwords
192              
193             =head1 NAME
194              
195             Perl::Critic::Module::Build - Customization of L<Module::Build> for L<Perl::Critic>.
196              
197              
198             =head1 DESCRIPTION
199              
200             This is a custom subclass of L<Module::Build> (actually,
201             L<Perl::Critic::Module::Build::Standard>) that enhances existing functionality
202             and adds more for the benefit of installing and developing L<Perl::Critic>.
203             The following actions have been added or redefined:
204              
205              
206             =head1 ACTIONS
207              
208             =over
209              
210             =item policysummary
211              
212             Generates the F<PolicySummary.pod> file. This should only be used by
213             C<Perl::Critic> developers. This action is also invoked by the C<authortest>
214             action, so the F<PolicySummary.pod> file will be generated whenever you create
215             a distribution with the C<dist> or C<distdir> targets.
216              
217              
218             =item nytprof
219              
220             Runs perlcritic under the L<Devel::NYTProf> profiler and generates
221             an HTML report in F<nytprof/index.html>.
222              
223              
224             =back
225              
226              
227             =head1 AUTHOR
228              
229             Elliot Shank <perl@galumph.com>
230              
231             =head1 COPYRIGHT
232              
233             Copyright (c) 2007-2023 Elliot Shank.
234              
235             This program is free software; you can redistribute it and/or modify
236             it under the same terms as Perl itself. The full text of this license
237             can be found in the LICENSE file included with this module.
238              
239             =cut
240              
241              
242             ##############################################################################
243             # Local Variables:
244             # mode: cperl
245             # cperl-indent-level: 4
246             # fill-column: 78
247             # indent-tabs-mode: nil
248             # c-indentation-style: bsd
249             # End:
250             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :