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