1#######################################################################
2#      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/distributions/Perl-Critic-More/inc/Perl/Critic/Module/Build.pm $
3#     $Date: 2013-10-25 14:41:43 -0700 (Fri, 25 Oct 2013) $
4#   $Author: thaljef $
5# $Revision: 4188 $
6########################################################################
7
8package Perl::Critic::Module::Build;
9
10use 5.006001;
11
12use strict;
13use warnings;
14use Carp;
15use English qw< $OS_ERROR $EXECUTABLE_NAME -no_match_vars >;
16
17use base 'Module::Build';
18
19
20sub ACTION_test {
21    my ($self, @arguments) = @_;
22
23    $self->depends_on('manifest');
24    $self->depends_on('distmeta');
25
26    return $self->SUPER::ACTION_test(@arguments);
27}
28
29
30sub ACTION_authortest {
31    my ($self) = @_;
32
33    $self->_authortest_dependencies();
34    $self->depends_on('test');
35
36    return;
37}
38
39
40sub ACTION_authortestcover {
41    my ($self) = @_;
42
43    $self->_authortest_dependencies();
44    $self->depends_on('testcover');
45
46    return;
47}
48
49
50sub ACTION_distdir {
51    my ($self, @arguments) = @_;
52
53    $self->depends_on('authortest');
54
55    return $self->SUPER::ACTION_distdir(@arguments);
56}
57
58
59sub ACTION_nytprof {
60    my ($self) = @_;
61    $self->depends_on('build');
62    $self->_run_nytprof();
63    return;
64}
65
66
67sub ACTION_manifest {
68    my ($self, @arguments) = @_;
69
70    if (-e 'MANIFEST') {
71        unlink 'MANIFEST' or die "Can't unlink MANIFEST: $OS_ERROR";
72    }
73
74    return $self->SUPER::ACTION_manifest(@arguments);
75}
76
77
78sub tap_harness_args {
79    my ($self) = @_;
80    return  $self->_tap_harness_args() if $ENV{RUNNING_UNDER_TEAMCITY};
81    return;
82}
83
84
85sub _tap_harness_args {
86    return {formatter_class => 'TAP::Formatter::TeamCity', merge => 1};
87}
88
89
90sub _authortest_dependencies {
91    my ($self) = @_;
92
93    $self->depends_on('build');
94    $self->depends_on('manifest');
95    $self->depends_on('distmeta');
96
97    $self->test_files( qw< t xt/author > );
98    $self->recursive_test_files(1);
99
100    return;
101}
102
103
104sub _run_nytprof {
105    my ($self) = @_;
106
107
108    eval {require Devel::NYTProf}
109      or croak 'Devel::NYTProf is required to run nytprof';
110
111    eval {require File::Which; File::Which->import('which'); 1}
112      or croak 'File::Which is required to run nytprof';
113
114    my $nytprofhtml = which('nytprofhtml')
115      or croak 'Could not find nytprofhtml in your PATH';
116
117    my $this_perl = $EXECUTABLE_NAME;
118    my @perl_args = qw(-Iblib/lib -d:NYTProf blib/script/perlcritic);
119    my @perlcritic_args = qw(-noprofile -severity=1 -theme=core -exclude=TidyCode -exclude=PodSpelling blib);
120    warn join q{ }, 'Running:', $this_perl, @perl_args, @perlcritic_args, "\n";
121
122    my $status_perlcritic = system $this_perl, @perl_args, @perlcritic_args;
123    croak "perlcritic failed with status $status_perlcritic."
124      if $status_perlcritic == 1;
125
126    my $status_nytprofhtml = system $nytprofhtml;
127    croak "nytprofhtml failed with status $status_nytprofhtml."
128      if $status_nytprofhtml;
129
130    return;
131}
132
1331;
134
135
136__END__
137
138#-----------------------------------------------------------------------------
139
140=pod
141
142=for stopwords
143
144=head1 NAME
145
146Perl::Critic::Module::Build - Customization of L<Module::Build> for L<Perl::Critic>.
147
148
149=head1 DESCRIPTION
150
151This is a custom subclass of L<Module::Build> that enhances existing
152functionality and adds more for the benefit of installing and
153developing L<Perl::Critic>.
154
155
156=head1 METHODS
157
158=over
159
160=item C<ACTION_test()>
161
162In addition to the standard action, this adds a dependency upon the
163C<manifest> action.
164
165
166=item C<ACTION_authortest()>
167
168Runs the regular tests plus the author tests (those in F<xt/author>).
169It used to be the case that author tests were run if an environment
170variable was set or if a F<.svn> directory existed.  What ended up
171happening was that people that had that environment variable set for
172other purposes or who had done a checkout of the code repository would
173run those tests, which would fail, and we'd get bug reports for
174something not expected to run elsewhere.  Now, you've got to
175explicitly ask for the author tests to be run.
176
177
178=item C<ACTION_authortestcover()>
179
180As C<authortest> is to the standard C<test> action, C<authortestcover>
181is to the standard C<testcover> action.
182
183
184=item C<ACTION_distdir()>
185
186In addition to the standard action, this adds a dependency upon the
187C<authortest> action so you can't do a release without passing the
188author tests.
189
190=item C<ACTION_nytprof()>
191
192Runs perlcritic under the L<Devel::NYTProf> profiler and generates
193an HTML report in F<nytprof/index.html>.
194
195
196=back
197
198
199=head1 AUTHOR
200
201Elliot Shank <perl@galumph.com>
202
203=head1 COPYRIGHT
204
205Copyright (c) 2007-2009 Elliot Shank.  All rights reserved.
206
207This program is free software; you can redistribute it and/or modify
208it under the same terms as Perl itself.  The full text of this license
209can be found in the LICENSE file included with this module.
210
211=cut
212
213
214##############################################################################
215# Local Variables:
216#   mode: cperl
217#   cperl-indent-level: 4
218#   fill-column: 78
219#   indent-tabs-mode: nil
220#   c-indentation-style: bsd
221# End:
222# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :
223