Login
Get generation of t/NamingConventions/Capitalization.run in place.
[gknop/Perl-Critic.git] / inc / Perl / Critic / BuildUtilities.pm
CommitLineData
34cc6052
ES
1##############################################################################
2# $URL$
3# $Date$
4# $Author$
5# $Revision$
6##############################################################################
7
8package Perl::Critic::BuildUtilities;
9
df6dee2b 10use 5.006001;
34cc6052
ES
11use strict;
12use warnings;
13
7963ad6d 14use English q<-no_match_vars>;
70f3f307 15
33e51b94 16our $VERSION = '1.092';
34cc6052
ES
17
18use base qw{ Exporter };
19
496afbe0 20our @EXPORT_OK = qw<
70f3f307
ES
21 recommended_module_versions
22 test_wrappers_to_generate
496afbe0 23 get_PL_files
70f3f307 24 dump_unlisted_or_optional_module_versions
7963ad6d 25 emit_tar_warning_if_necessary
496afbe0
ES
26>;
27
28
7963ad6d
ES
29use Devel::CheckOS qw< os_is >;
30
34cc6052
ES
31
32sub recommended_module_versions {
33 return (
34 'File::HomeDir' => 0,
35 'Perl::Tidy' => 0,
eb6e0777 36 'Readonly::XS' => 0,
90c0067c 37 'Regexp::Parser' => '0.20',
7b69c24b 38 'Term::ANSIColor' => 0,
34cc6052
ES
39
40 # All of these are for Documentation::PodSpelling
41 'File::Which' => 0,
42 'IPC::Open2' => 1,
43 'Pod::Spell' => 1,
44 'Text::ParseWords' => 3,
45 );
46}
47
496afbe0 48
34cc6052 49sub test_wrappers_to_generate {
70f3f307 50 my @tests_to_be_wrapped = qw<
34cc6052
ES
51 t/00_modules.t
52 t/01_config.t
53 t/01_config_bad_perlcriticrc.t
2798ab37 54 t/01_policy_config.t
34cc6052
ES
55 t/02_policy.t
56 t/03_pragmas.t
9b1b52f4 57 t/03_useless_pragmas.t
894d344a 58 t/04_optionsprocessor.t
34cc6052
ES
59 t/05_utils.t
60 t/05_utils_ppi.t
0d512192 61 t/05_utils_pod.t
34cc6052
ES
62 t/06_violation.t
63 t/07_perlcritic.t
64 t/08_document.t
65 t/09_theme.t
66 t/10_userprofile.t
67 t/11_policyfactory.t
68 t/12_policylisting.t
71ef7d49 69 t/12_themelisting.t
34cc6052
ES
70 t/13_bundled_policies.t
71 t/14_policy_parameters.t
72 t/15_statistics.t
8eb8a2e5 73 t/20_policies.t
492ab247
JRT
74 t/20_policy_pod_spelling.t
75 t/20_policy_require_tidy_code.t
0d512192 76 xt/author/80_policysummary.t
34cc6052 77 t/92_memory_leaks.t
0d512192 78 xt/author/94_includes.t
70f3f307 79 >;
34cc6052
ES
80
81 return
82 map
0d512192 83 { "xt/author/generated/${_}_without_optional_dependencies.t" }
34cc6052
ES
84 @tests_to_be_wrapped;
85}
86
8ddad51b
ES
87my @TARGET_FILES = qw<
88 lib/Perl/Critic/PolicySummary.pod
89 t/ControlStructures/ProhibitNegativeExpressionsInUnlessAndUntilConditions.run
d33d2185 90 t/NamingConventions/Capitalization.run
8ddad51b
ES
91 t/Variables/RequireLocalizedPunctuationVars.run
92>;
93
496afbe0 94sub get_PL_files {
8ddad51b 95 my %PL_files = map { ( "$_.PL" => $_ ) } @TARGET_FILES;
6d34b243 96
90806b21 97 $PL_files{'xt/author/generate_without_optional_dependencies_wrappers.PL'} =
0d512192 98 [ test_wrappers_to_generate() ];
496afbe0 99
6d34b243 100 return \%PL_files;
496afbe0
ES
101}
102
70f3f307
ES
103sub dump_unlisted_or_optional_module_versions {
104 print
105 "\nVersions of optional/unlisted/indirect dependencies:\n\n";
106
107 my @unlisted_modules = (
108 qw<
70f3f307
ES
109 >,
110 keys %{ { recommended_module_versions() } },
111 );
112
113 foreach my $module (sort @unlisted_modules) {
114 my $version;
115
910d5187 116 if ($module eq 'Readonly::XS') {
f56c0ad2 117 eval 'use Readonly; use Readonly::XS; $version = $Readonly::XS::VERSION;';
910d5187
ES
118 }
119 else {
120 eval "use $module; \$version = \$${module}::VERSION;";
121 }
70f3f307
ES
122 if ($EVAL_ERROR) {
123 $version = 'not installed';
124 } elsif (not defined $version) {
125 $version = 'undef';
126 }
127
128 print " $module = $version\n";
129 }
130
131 print "\n";
132
133 return;
134}
34cc6052 135
7963ad6d
ES
136sub emit_tar_warning_if_necessary {
137 if ( os_is( qw<Solaris> ) ) {
138 print <<'END_OF_TAR_WARNING';
139NOTE: tar(1) on some Solaris systems cannot deal well with long file
140names.
141
142If you get warnings about missing files below, please ensure that you
143extracted the Perl::Critic tarball using GNU tar.
144
145END_OF_TAR_WARNING
146 }
147}
148
34cc6052
ES
1491;
150
151__END__
152
153=head1 NAME
154
155Perl::Critic::BuildUtilities - Common bits of compiling Perl::Critic.
156
157
158=head1 DESCRIPTION
159
160Various utilities used in assembling Perl::Critic, primary for use by
161*.PL programs that generate code.
162
163
164=head1 IMPORTABLE SUBROUTINES
165
166=over
167
168=item C<recommended_module_versions()>
169
170Returns a hash mapping between recommended (but not required) modules
171for Perl::Critic and the minimum version required of each module,
172
173
174=item C<test_wrappers_to_generate()>
175
176Returns a list of test wrappers to be generated by
90806b21 177F<xt/author/generate_without_optional_dependencies_wrappers.PL>.
34cc6052 178
496afbe0
ES
179
180=item C<get_PL_files()>
181
182Returns a reference to a hash with a mapping from the name of a .PL
183program to an array of the parameters to be passed to it, suited for
184use by L<Module::Build::API/"PL_files"> or
185L<ExtUtils::MakeMaker/"PL_FILES">. May print to C<STDOUT> messages
186about what it is doing.
187
188
70f3f307
ES
189=item C<dump_unlisted_or_optional_module_versions()>
190
191Prints to C<STDOUT> a list of all the unlisted (e.g. things in core
11f53956
ES
192like L<Exporter|Exporter>), optional (e.g.
193L<File::Which|File::Which>), or potentially indirect (e.g.
194L<Readonly::XS|Readonly::XS>) dependencies, plus their versions, if
70f3f307
ES
195they're installed.
196
34cc6052 197
7963ad6d
ES
198=item C<emit_tar_warning_if_necessary()>
199
200On some Solaris systems, C<tar(1)> can't deal with long file names and
201thus files are not correctly extracted from the tarball. So this
202prints a warning if the current system is Solaris.
203
204
34cc6052
ES
205=back
206
207
208=head1 AUTHOR
209
210Elliot Shank C<< <perl@galumph.com> >>
211
212
213=head1 LICENCE AND COPYRIGHT
214
215Copyright (c) 2007, Elliot Shank C<< <perl@galumph.com> >>. All rights
216reserved.
217
218This program is free software; you can redistribute it and/or modify
219it under the same terms as Perl itself. The full text of this license
220can be found in the LICENSE file included with this module.
221
222=cut
223
224##############################################################################
225# Local Variables:
226# mode: cperl
227# cperl-indent-level: 4
228# fill-column: 78
229# indent-tabs-mode: nil
230# c-indentation-style: bsd
231# End:
96fed375 232# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :