Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 1171 lines (903 sloc) 33.47 kb
a4123f8 @abw 2.04b
authored
1 #!/usr/bin/perl -w # -*- perl -*-
2
3 use strict;
4
5 use lib qw( ./lib );
6 use Template;
7 use ExtUtils::MakeMaker;
c8d76d4 @abw *** empty log message ***
authored
8 use Cwd;
3ebfa07 @abw Initial revision
authored
9
e39913f @abw *** empty log message ***
authored
10 select STDERR;
11 $| = 1;
12 select STDOUT;
13
a4123f8 @abw 2.04b
authored
14 use vars qw( $TT_VERSION $TT_PREFIX $TT_IMAGES $TT_RUN_DBI
ca4050f @abw prep for 2.02
authored
15 $TT_BUILD_DOCS $TT_SPLASH_DOCS $TT_EXAMPLES
a4123f8 @abw 2.04b
authored
16 $TT_LATEX_ENABLE $TT_LATEX_PATH $TT_PDFLATEX_PATH $TT_DVIPS_PATH
9be7d64 @abw approaching 2.04d
authored
17 $TT_XS_ENABLE $TT_XS_DEFAULT
a4123f8 @abw 2.04b
authored
18 $TT_SPLASH_THEME $TT_QUIET $TT_ACCEPT $TT_YES );
19
20 # check O/S to set sensible defaults
9be7d64 @abw approaching 2.04d
authored
21
22 my ($WIN32, $FLAVOUR, $PREFIX, $IMAGES, $MAKE);
dd62af1 @abw * Applied Chris' patch to fix win => MSWin32
authored
23 if ($^O eq 'MSWin32') { # any others also?
a4123f8 @abw 2.04b
authored
24 $WIN32 = 1;
25 $FLAVOUR = 'Win32';
26 $PREFIX = 'C:/Program Files/Template Toolkit 2';
9be7d64 @abw approaching 2.04d
authored
27 $IMAGES = '/tt2/images';
a4123f8 @abw 2.04b
authored
28 $MAKE = 'nmake';
29 }
30 else {
31 $WIN32 = 0;
32 $FLAVOUR = 'Unix';
33 $PREFIX = '/usr/local/tt2';
9be7d64 @abw approaching 2.04d
authored
34 $IMAGES = '/tt2/images';
a4123f8 @abw 2.04b
authored
35 $MAKE = 'make';
36 }
37
9be7d64 @abw approaching 2.04d
authored
38
39 # read command line args putting TT_* into $ttconfig and
40 # everything else (regular Makefile.PL args, e.g. PREFIX)
41 # goes into $config
42
a4123f8 @abw 2.04b
authored
43 my (%config, %ttconfig);
44 while ($_ = shift) {
45 my ($k, $v) = split(/=/);
46 if ($k =~ /^TT/) {
47 $ttconfig{ $k } = $v || 0;
48 }
49 else {
50 $config{ $k } = $v || 0;
51 }
52 };
53
9be7d64 @abw approaching 2.04d
authored
54
55 # print help if they asked for it
56
a4123f8 @abw 2.04b
authored
57 if (exists $ttconfig{ TT_HELP }) {
58 print <<EOF;
59 The following options can be specified as command line
60 arguments to 'perl Makefile.PL'. e.g.
61
9be7d64 @abw approaching 2.04d
authored
62 perl Makefile.PL TT_PREFIX=/my/tt2/dir TT_ACCEPT=y
63
64 TT_PREFIX installation prefix ($PREFIX)
65 TT_IMAGES images URL (/tt2/images)
66 TT_DOCS build HTML docs (y)
67 TT_SPLASH use Splash! for docs (y)
68 TT_THEME Splash! theme (default)
69 TT_EXAMPLES build HTML examples (y)
70 TT_XS_ENABLE Enable XS Stash (y)
71 TT_XS_DEFAULT Use XS Stash by default (y)
72 TT_DBI run DBI tests (y if DBI installed)
73
74 TT_LATEX install LaTeX filter (y if LaTeX found)
75 TT_LATEX_PATH path to latex (system dependant)
76 TT_PDFLATEX_PATH path to pdflatex ( " " " )
77 TT_DVIPS_PATH path to dvips ( " " " )
a4123f8 @abw 2.04b
authored
78
9be7d64 @abw approaching 2.04d
authored
79 TT_QUIET no messages (n)
80 TT_ACCEPT accept defaults (n)
a4123f8 @abw 2.04b
authored
81
82 By default, the Makefile.PL runs in interactive mode,
83 prompting for confirmation of the various configuration
84 options. Setting the TT_ACCEPT option causes the default
85 value (possibly modified by other command line options)
86 to be accepted. The TT_QUIET option can also be set to
87 suppress the prompt messages.
88
89 EOF
90 exit(0);
91 }
ca4050f @abw prep for 2.02
authored
92
9be7d64 @abw approaching 2.04d
authored
93 # these global package variables are the main flags used
94 # in this script, here defaulted to sensible values
95
a4123f8 @abw 2.04b
authored
96 $TT_VERSION = $Template::VERSION;
97 $TT_PREFIX = $PREFIX;
9be7d64 @abw approaching 2.04d
authored
98 $TT_IMAGES = $IMAGES;
f4df3b6 @abw approach v2.03
authored
99 $TT_RUN_DBI = 'y';
100 $TT_BUILD_DOCS = 'y';
101 $TT_SPLASH_DOCS = 'y';
102 $TT_EXAMPLES = 'y';
103 $TT_SPLASH_THEME = 'default';
9be7d64 @abw approaching 2.04d
authored
104 $TT_XS_ENABLE = 'y';
105 $TT_XS_DEFAULT = 'y';
a4123f8 @abw 2.04b
authored
106 $TT_LATEX_ENABLE = 'y';
9be7d64 @abw approaching 2.04d
authored
107 $TT_LATEX_PATH = '';
108 $TT_PDFLATEX_PATH = '';
109 $TT_DVIPS_PATH = '';
a4123f8 @abw 2.04b
authored
110 $TT_QUIET = 'n';
111 $TT_ACCEPT = 'n';
f4df3b6 @abw approach v2.03
authored
112
46e4eb8 @abw * Added new colour theme called 'leon'
authored
113 my $TT_SPLASH_FG = '';
114 my $TT_SPLASH_BG = '';
115 my $TT_SPLASH_FT = '';
116 my $TT_SPLASH_BT = '';
ca4050f @abw prep for 2.02
authored
117
118 my $DEFAULTS_FILE = '.defaults.cfg';
48634a1 @abw *** empty log message ***
authored
119 my $DBI_CONFIG_FILE = 't/dbi_test.cfg';
c8d76d4 @abw *** empty log message ***
authored
120 my $TT_DOCS_CFG = 'docs/ttree.cfg';
121 my $TT_EXAMPLE_CFG = 'examples/ttree.cfg';
ca4050f @abw prep for 2.02
authored
122 my $DEFAULTS = '';
911a5e3 @abw *** empty log message ***
authored
123
ca4050f @abw prep for 2.02
authored
124 if (-f $DEFAULTS_FILE) {
125 require $DEFAULTS_FILE;
126 $DEFAULTS = " read from '$DEFAULTS_FILE'";
127 }
128
9be7d64 @abw approaching 2.04d
authored
129 $TT_PREFIX = $ttconfig{ TT_PREFIX } if $ttconfig{ TT_PREFIX };
130 $TT_IMAGES = $ttconfig{ TT_IMAGES } if $ttconfig{ TT_IMAGES };
131 $TT_SPLASH_THEME = $ttconfig{ TT_THEME } if $ttconfig{ TT_THEME };
132 $TT_LATEX_PATH = $ttconfig{ TT_LATEX_PATH } if $ttconfig{ TT_LATEX_PATH };
133 $TT_PDFLATEX_PATH = $ttconfig{ TT_PDFLATEX_PATH } if $ttconfig{ TT_PDFLATEX_PATH };
134 $TT_DVIPS_PATH = $ttconfig{ TT_DVIPS_PATH } if $ttconfig{ TT_DVIPS_PATH };
135 $TT_RUN_DBI = $ttconfig{ TT_DBI } if defined $ttconfig{ TT_DBI };
136 $TT_BUILD_DOCS = $ttconfig{ TT_DOCS } if defined $ttconfig{ TT_DOCS };
137 $TT_SPLASH_DOCS = $ttconfig{ TT_SPLASH } if defined $ttconfig{ TT_SPLASH };
138 $TT_EXAMPLES = $ttconfig{ TT_EXAMPLES } if defined $ttconfig{ TT_EXAMPLES };
139 $TT_LATEX_ENABLE = $ttconfig{ TT_LATEX } if defined $ttconfig{ TT_LATEX };
140 $TT_XS_ENABLE = $ttconfig{ TT_XS_ENABLE } if defined $ttconfig{ TT_XS_ENABLE };
141 $TT_XS_DEFAULT = $ttconfig{ TT_XS_DEFAULT } if defined $ttconfig{ TT_XS_DEFAULT };
142 $TT_QUIET = $ttconfig{ TT_QUIET } if defined $ttconfig{ TT_QUIET };
143 $TT_ACCEPT = $ttconfig{ TT_ACCEPT } if defined $ttconfig{ TT_ACCEPT };
144
145 foreach ($TT_RUN_DBI, $TT_BUILD_DOCS, $TT_SPLASH_DOCS, $TT_EXAMPLES,
146 $TT_LATEX_ENABLE, $TT_XS_ENABLE, $TT_XS_DEFAULT ) {
a4123f8 @abw 2.04b
authored
147 $_ = 'n' if ! $_;
148 }
149 $TT_ACCEPT = 0 if $TT_ACCEPT eq 'n';
150 $TT_QUIET = 0 if $TT_QUIET eq 'n';
151 $TT_QUIET = 0 unless $TT_ACCEPT;
152
ca4050f @abw prep for 2.02
authored
153 my $SPLASH_STYLES = {
154 default => [ 'lilac', 'mauve' ],
155 aqua => [ 'aqua', 'marine' ],
156 grey => [ 'grey75', 'grey50' ],
157 blue => [ 'grey75', 'blue75' ],
158 red => [ 'grey75', 'red75' ],
159 green => [ 'grey75', 'green75' ],
46e4eb8 @abw * Added new colour theme called 'leon'
authored
160 leon => [ 'red75', 'orange', 'white', 'black' ],
ca4050f @abw prep for 2.02
authored
161 };
162
c542301 @abw *** empty log message ***
authored
163
a4123f8 @abw 2.04b
authored
164 #========================================================================
165
166 welcome_message();
167 version_check();
c7d3d41 @abw * removed mandatory modules check from Makefile.PL to keep CPAN module
authored
168 # mandatory_modules();
a4123f8 @abw 2.04b
authored
169 optional_modules();
9be7d64 @abw approaching 2.04d
authored
170 optional_stash_xs();
a4123f8 @abw 2.04b
authored
171 optional_latex();
172 optional_extras();
173 splash_images();
174 html_docs();
175 html_docstyle();
176 html_examples();
177 write_defaults();
178
179 print "\n";
180
181
182 #------------------------------------------------------------------------
183 # build options and write Makefile
184 #------------------------------------------------------------------------
185
186 package MY;
187
188 sub postamble {
189 return '' unless $main::TT_PREFIX;
190 my $amble =<<'EOF';
191 tt2_install ::
192 @$(PERL) bin/tt2inst -v "$(TT_PREFIX)"
193
194 tt2_splash ::
582a703 @abw * Applied a patch from Christian Schaffner which fixes a problem in
authored
195 @$(PERL) -I$(INST_LIB) -I$(INST_ARCHLIB) bin/gifsplash -v -i "$(TT_PREFIX)"
a4123f8 @abw 2.04b
authored
196
197 EOF
198 $amble .=<<EOF if $main::TT_BUILD_DOCS;
199 tt2_html_docs ::
582a703 @abw * Applied a patch from Christian Schaffner which fixes a problem in
authored
200 \@\$(PERL) -I\$(INST_LIB) -I\$(INST_ARCHLIB) bin/ttree -v -f "\$(TT_PREFIX)/$TT_DOCS_CFG"
a4123f8 @abw 2.04b
authored
201
202 EOF
203 $amble .=<<EOF if $main::TT_EXAMPLES;
204 tt2_examples ::
582a703 @abw * Applied a patch from Christian Schaffner which fixes a problem in
authored
205 \@\$(PERL) -I\$(INST_LIB) -I\$(INST_ARCHLIB) bin/ttree -v -f "\$(TT_PREFIX)/$TT_EXAMPLE_CFG"
a4123f8 @abw 2.04b
authored
206
207 EOF
208 return $amble;
209 }
210
211 sub install {
212 my $class = shift;
213 my $basic = $class->SUPER::install(@_);
214 my $add = 'tt2_install tt2_splash';
215 $add .= ' tt2_html_docs' if $main::TT_BUILD_DOCS;
216 $add .= ' tt2_examples' if $main::TT_EXAMPLES;
217 $basic =~ s/^(install\s+::\s+.*)$/$1 $add/m
218 if $main::TT_PREFIX;
219 $basic;
220 }
221
222 sub constants {
223 my $class = shift;
224 my $basic = $class->SUPER::constants(@_);
225 $basic = "TT_PREFIX = $main::TT_PREFIX\n$basic"
226 if $main::TT_PREFIX;
227 $basic;
228 }
229
230 package main;
231
232 my %opts = (
233 %config,
234 'NAME' => 'Template',
235 'DISTNAME' => 'Template-Toolkit',
236 'VERSION_FROM' => 'lib/Template.pm',
237 'EXE_FILES' => [ 'bin/tpage', 'bin/ttree' ],
238 'PMLIBDIRS' => [ 'lib' ],
9be7d64 @abw approaching 2.04d
authored
239 'DIR' => [ ],
c7d3d41 @abw * removed mandatory modules check from Makefile.PL to keep CPAN module
authored
240 'PREREQ_PM' => {
241 'AppConfig' => 1.52,
242 'File::Spec' => 0.6,
243 },
a4123f8 @abw 2.04b
authored
244 'dist' => {
245 'COMPRESS' => 'gzip',
246 'SUFFIX' => 'gz',
247 },
248 );
249
9be7d64 @abw approaching 2.04d
authored
250 push @{ $opts{'DIR'} }, 'xs' if $TT_XS_ENABLE;
251
a4123f8 @abw 2.04b
authored
252 if ($ExtUtils::MakeMaker::VERSION >= 5.43) {
253 $opts{ AUTHOR } = 'Andy Wardley <abw@kfs.org>';
254 $opts{ ABSTRACT } =
255 'a fast, flexible and extensible template processing system',
256 }
257
258
259 WriteMakefile( %opts );
260
261 if ($WIN32) {
262 print <<EOF;
263
264 Configuration complete. You should now run '$MAKE', '$MAKE test' and
265 then '$MAKE install'. See the README file for further information.
266 EOF
267 }
268
269 message(<<EOF) if $TT_BUILD_DOCS;
270
9be7d64 @abw approaching 2.04d
authored
271
272 Installation Notes
273 ------------------
274
a4123f8 @abw 2.04b
authored
275 Please note that the installation of the optional components and
276 building of the HTML documentation is performed at the "make install"
277 stage as the effective user at that time. This implies that this user
278 must have sufficient permission to install into the specified
279 directory and that all created directories and files will be owned by
280 them.
281
282 EOF
283
284 #========================================================================
285
286
287
288 #------------------------------------------------------------------------
289 # welcome_message()
290 #
291 # Print opening banner.
292 #------------------------------------------------------------------------
293
294 sub welcome_message {
295 print(<<EOF);
296
297 Template Toolkit Version $TT_VERSION
c542301 @abw *** empty log message ***
authored
298 =============================
911a5e3 @abw *** empty log message ***
authored
299
ca4050f @abw prep for 2.02
authored
300 Using $FLAVOUR defaults$DEFAULTS.
9be7d64 @abw approaching 2.04d
authored
301
302 Run 'perl Makefile.PL TT_HELP' for a summary of options.
48634a1 @abw *** empty log message ***
authored
303 EOF
a4123f8 @abw 2.04b
authored
304 print "Messages suppressed (TT_QUIET). " if $TT_QUIET;
305 print "Accepting defaults automatically (TT_ACCEPT)." if $TT_ACCEPT;
306 }
307
308
48634a1 @abw *** empty log message ***
authored
309
310 #------------------------------------------------------------------------
a4123f8 @abw 2.04b
authored
311 # version_check()
312 #
313 # Check for pre-version 2.00 installation and issue warning
48634a1 @abw *** empty log message ***
authored
314 #------------------------------------------------------------------------
315
a4123f8 @abw 2.04b
authored
316 sub version_check {
317 eval "use Template";
318 unless ($@ or $Template::VERSION =~ /^2/) {
319 warn(<<EOF) unless $TT_QUIET;
48634a1 @abw *** empty log message ***
authored
320
c542301 @abw *** empty log message ***
authored
321 IMPORTANT NOTE:
a4123f8 @abw 2.04b
authored
322
48634a1 @abw *** empty log message ***
authored
323 You have version $Template::VERSION of the Template Toolkit installed.
25a8d8e @abw *** empty log message ***
authored
324
82cbea8 @abw version 2.00
authored
325 There are some minor incompatabilities between version 1 and 2
48634a1 @abw *** empty log message ***
authored
326 of the Template Toolkit which you should be aware of. Installing
327 this version will overwrite your version $Template::VERSION files
328 unless you take measures to install one or the other version in a
82cbea8 @abw version 2.00
authored
329 different location (i.e. perl Makefile.PL PREFIX=/other/path).
48634a1 @abw *** empty log message ***
authored
330
331 Please consult the README and Changes file for further details.
332 Most of the changes are in the more obscure features and
333 directives so hopefully you will find the upgrade process fairly
9be7d64 @abw approaching 2.04d
authored
334 painless. If you're feeling brave, then answer 'y', otherwise 'n'.
25a8d8e @abw *** empty log message ***
authored
335
336 EOF
a4123f8 @abw 2.04b
authored
337 exit unless ttprompt("Do you want to continue?", 'y') =~ /y/i;
338 }
48634a1 @abw *** empty log message ***
authored
339 }
340
a4123f8 @abw 2.04b
authored
341
48634a1 @abw *** empty log message ***
authored
342 #------------------------------------------------------------------------
a4123f8 @abw 2.04b
authored
343 # mandatory_modules()
344 #
345 # Detect mandatory module
c8d76d4 @abw *** empty log message ***
authored
346 #------------------------------------------------------------------------
347
a4123f8 @abw 2.04b
authored
348 sub mandatory_modules {
349 eval "use AppConfig";
350 if ($@ or $AppConfig::VERSION < 1.52) {
351 die(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
352
353 The Template Toolkit requires that the AppConfig module (version 1.52
354 or later) first be installed. This is used by the 'ttree' program for
355 reading command line options and configuration files. It is available
356 from CPAN:
357
358 http://www.cpan.org/authors/Andy_Wardley/
359
360 EOF
a4123f8 @abw 2.04b
authored
361 }
c8d76d4 @abw *** empty log message ***
authored
362
a4123f8 @abw 2.04b
authored
363 eval "use File::Spec";
364 if ($@ or $File::Spec::VERSION < 0.6) {
365 die(<<EOF);
911a5e3 @abw *** empty log message ***
authored
366
f4df3b6 @abw approach v2.03
authored
367 The Template Toolkit requires that the File::Spec module (version 0.6
911a5e3 @abw *** empty log message ***
authored
368 or later) first be installed. This is used by the File plugin. It is
369 available from CPAN:
370
371 http://search.cpan.org/search?dist=File-Spec
372
373 EOF
a4123f8 @abw 2.04b
authored
374 }
911a5e3 @abw *** empty log message ***
authored
375 }
376
377
a4123f8 @abw 2.04b
authored
378
c8d76d4 @abw *** empty log message ***
authored
379 #------------------------------------------------------------------------
a4123f8 @abw 2.04b
authored
380 # optional_modules()
381 #
382 # Detect additional modules required by plugins (just for fun)
48634a1 @abw *** empty log message ***
authored
383 #------------------------------------------------------------------------
25a8d8e @abw *** empty log message ***
authored
384
a4123f8 @abw 2.04b
authored
385 sub optional_modules {
386 message(<<EOF);
48634a1 @abw *** empty log message ***
authored
387
9be7d64 @abw approaching 2.04d
authored
388 External Modules
389 ----------------
390
82cbea8 @abw version 2.00
authored
391 The Template Toolkit includes a number of plugin modules, some of
392 which interface to external Perl modules available from CPAN. All the
393 plugins will be installed regardless so that they will automatically
394 work as and when you install the relevant modules. The tests will be
395 skipped for plugins that require external modules not currently
396 available on your system.
e39913f @abw *** empty log message ***
authored
397
398 EOF
48634a1 @abw *** empty log message ***
authored
399
a4123f8 @abw 2.04b
authored
400 foreach my $mods ( [ 'Text::Autoformat' => \&check_taf ],
401 [ 'GD' => undef ],
402 [ 'GD::Text' => undef ],
403 [ 'GD::Graph' => undef ],
404 [ 'GD::Graph3d' => undef ],
405 [ 'Date::Calc' => undef ],
8703940 @abw prep 2.05
authored
406 [ 'Pod::POM' => undef ],
e9d3021 @abw * fixed up bug in XS stash introduced with SCALAR_OPS lookup added to fa...
authored
407 [ 'Tie::DBI' => undef ],
a4123f8 @abw 2.04b
authored
408 [ 'XML::DOM' => \&check_dom ],
409 [ 'XML::RSS' => \&check_rss ],
410 [ 'XML::XPath' => \&check_xpath ],
411 [ 'DBI' => \&dbi_config ] ) {
412 my ($module, $code) = ref $mods ? @$mods : ($mods, 0);
413
414 printf(" %-16s ", $module) unless $TT_QUIET;
415 eval "use $module";
416 if ($@) {
417 nope("module not installed");
418 }
419 elsif ($code) {
420 &$code;
421 }
422 else {
423 no strict qw( refs );
424 my $ver = ${"$module\::VERSION"};
425 yep("version $ver installed");
426 }
82cbea8 @abw version 2.00
authored
427 }
e39913f @abw *** empty log message ***
authored
428 }
429
a4123f8 @abw 2.04b
authored
430
9be7d64 @abw approaching 2.04d
authored
431 #------------------------------------------------------------------------
432 # optional_stash_xs()
433 #
434 # Prompt for installation and default use of XS Stash.
435 #------------------------------------------------------------------------
436
437 sub optional_stash_xs {
438 # return if $TT_ACCEPT && (! $TT_XS_ENABLE || $TT_XS_ENABLE eq 'n');
439
440 message(<<EOF);
441
442
443 XS Stash: TT2 now twice as fast!
444 --------------------------------
445
dd62af1 @abw * Applied Chris' patch to fix win => MSWin32
authored
446 We have a new high speed version of the Template::Stash. It's
9be7d64 @abw approaching 2.04d
authored
447 a Perl XS module which can evaluate templates about twice as fast as
e9d3021 @abw * fixed up bug in XS stash introduced with SCALAR_OPS lookup added to fa...
authored
448 the pure-Perl version. It is stable and reliable but be warned that
449 it doesn't yet support access to tied hashes (e.g. Tie::DBI) so for
450 certain applications you may need to explicitly use the regular stash.
9be7d64 @abw approaching 2.04d
authored
451
46e4eb8 @abw * Added new colour theme called 'leon'
authored
452 You can choose to build the XS stash module and enable it by default
453 so that it is used automatically for all templates. If you build it
454 but don't enable it by default then you can use it something like
455 this:
9be7d64 @abw approaching 2.04d
authored
456
457 use Template;
458 use Template::Stash::XS;
459
460 my \$tt = new Template ({ STASH => new Template::Stash::XS, ... });
461
e9d3021 @abw * fixed up bug in XS stash introduced with SCALAR_OPS lookup added to fa...
authored
462 You can also enable the XS stash (or the regular stash if you opt to
463 use the XS stash by default) by setting the \$STASH package variable
464 in the Template/Config.pm module. See 'perldoc Template::Config' for
465 further details.
9be7d64 @abw approaching 2.04d
authored
466
467 EOF
468
469 $TT_XS_ENABLE = (ttprompt('Do you want to build the XS Stash module?',
470 $TT_XS_ENABLE) =~ /^y/i);
471
472 if ($TT_XS_ENABLE) {
473
474 $TT_XS_DEFAULT = (ttprompt('Do you want to use the XS Stash for all Templates?',
475 $TT_XS_DEFAULT) =~ /^y/i);
476
d941238 @abw prep 2.4d
authored
477 fix_file('lib/Template/Config.pm',
478 '$STASH',
479 $TT_XS_DEFAULT ? 'Template::Stash::XS' : 'Template::Stash');
9be7d64 @abw approaching 2.04d
authored
480 }
481 }
482
a4123f8 @abw 2.04b
authored
483
c8d76d4 @abw *** empty log message ***
authored
484 #------------------------------------------------------------------------
a4123f8 @abw 2.04b
authored
485 # optional_latex()
486 #
487 # Prompt for installation of latex filter
f4df3b6 @abw approach v2.03
authored
488 #------------------------------------------------------------------------
489
a4123f8 @abw 2.04b
authored
490 sub optional_latex {
9be7d64 @abw approaching 2.04d
authored
491 # return if $TT_ACCEPT && (! $TT_LATEX_ENABLE || $TT_LATEX_ENABLE eq 'n');
a4123f8 @abw 2.04b
authored
492
9be7d64 @abw approaching 2.04d
authored
493 $TT_LATEX_PATH ||= find_program($ENV{PATH}, "latex") || '';
494 $TT_PDFLATEX_PATH ||= find_program($ENV{PATH}, "pdflatex") || '';
495 $TT_DVIPS_PATH ||= find_program($ENV{PATH}, "dvips") || '';
a4123f8 @abw 2.04b
authored
496
497 message(<<EOF);
f4df3b6 @abw approach v2.03
authored
498
9be7d64 @abw approaching 2.04d
authored
499
500 LaTeX Support
501 -------------
502
f4df3b6 @abw approach v2.03
authored
503 TT2 supports PDF, DVI and PostScript output using the latex filter,
504 implemented with the programs pdflatex, latex and dvips.
505
506 Because the latex filter runs latex and pdflatex, template authors could
507 use this feature to include any arbitrary file in their latex input, or
508 also open an arbitrary output file, independent of the ABSOLUTE or
509 RELATIVE configuration settings. This might create a security concern at
510 your site. If you don't trust your template authors then don't enable
511 the latex filter.
512
513 I found the following locations for pdflatex, latex and dvips:
514 + pdflatex => $TT_PDFLATEX_PATH
515 + latex => $TT_LATEX_PATH
516 + dvips => $TT_DVIPS_PATH
517
518 EOF
519
a4123f8 @abw 2.04b
authored
520 if ( $TT_LATEX_PATH eq "" || $TT_PDFLATEX_PATH eq "" || $TT_DVIPS_PATH eq "" ) {
521 $TT_LATEX_ENABLE = 'n';
522 }
523 $TT_LATEX_ENABLE ||= 'y';
524 $TT_LATEX_ENABLE = (
525 ttprompt('Do you want to enable the latex filter?',
526 $TT_LATEX_ENABLE) =~ /^y/i
527 );
528 if ( $TT_LATEX_ENABLE ) {
529 if (ttprompt('Are the pdflatex, latex and dvips paths ok?', 'y') !~ /^y/i) {
530 $TT_PDFLATEX_PATH = ttprompt('pdflatex path', $TT_PDFLATEX_PATH);
531 $TT_LATEX_PATH = ttprompt('latex path', $TT_LATEX_PATH);
532 $TT_DVIPS_PATH = ttprompt('dvips path', $TT_DVIPS_PATH);
533 }
534 } else {
535 #
536 # Empty paths will cause the latex filter to throw an error
537 #
538 $TT_PDFLATEX_PATH = $TT_LATEX_PATH = $TT_DVIPS_PATH = "";
f4df3b6 @abw approach v2.03
authored
539 }
d941238 @abw prep 2.4d
authored
540
a4123f8 @abw 2.04b
authored
541 fix_file('lib/Template/Config.pm', '$PDFLATEX_PATH', $TT_PDFLATEX_PATH);
542 fix_file('lib/Template/Config.pm', '$LATEX_PATH', $TT_LATEX_PATH);
543 fix_file('lib/Template/Config.pm', '$DVIPS_PATH', $TT_DVIPS_PATH);
f4df3b6 @abw approach v2.03
authored
544 }
545
a4123f8 @abw 2.04b
authored
546
f4df3b6 @abw approach v2.03
authored
547 #------------------------------------------------------------------------
a4123f8 @abw 2.04b
authored
548 # optional_extras()
549 #
550 # Prompt for installation of optional libraries and other components
c8d76d4 @abw *** empty log message ***
authored
551 #------------------------------------------------------------------------
552
a4123f8 @abw 2.04b
authored
553 sub optional_extras {
554 message(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
555
9be7d64 @abw approaching 2.04d
authored
556
557 Optional Extras
558 ---------------
559
c8d76d4 @abw *** empty log message ***
authored
560 In additional to the Perl modules and POD documentation installed in
561 the usual way, the Template Toolkit distribution also contains a
562 number of optional components:
563
564 * Template libaries for basic HTML, Pod -> HTML, and PostScript
565
566 * Splash! - a stylish HTML user interface template library / widget set
567
568 * HTML documentation - distributed in template form for customisation
569
570 * Stylesheet templates to generate docs as vanilla HTML or using Splash!
571
572 * Examples - numerous examples of using the template libraries
573
574 If you want to install these optional components then you'll need to
575 specify a separate directory for them.
576
577 EOF
578
a4123f8 @abw 2.04b
authored
579 if (ttprompt('Do you want to install these components?', 'y') =~ /^y/i) {
580 message(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
581
582 You can chose any directory for the installation of the additional
911a5e3 @abw *** empty log message ***
authored
583 Template Toolkit components. The proposed default assumes a $FLAVOUR
584 flavour to your operating system (suggestions for suitable defaults
585 for other platforms welcome).
c8d76d4 @abw *** empty log message ***
authored
586
587 EOF
9be7d64 @abw approaching 2.04d
authored
588 $TT_PREFIX = ttprompt('Installation directory', $TT_PREFIX || $PREFIX);
a4123f8 @abw 2.04b
authored
589 }
590 else {
591 $TT_PREFIX = '';
592 }
593
594 fix_file('lib/Template/Config.pm', '$INSTDIR', $TT_PREFIX);
c8d76d4 @abw *** empty log message ***
authored
595 }
596
597
598
599 #------------------------------------------------------------------------
a4123f8 @abw 2.04b
authored
600 # splash_images()
601 #
602 # Prompt for Splash! image URL
c8d76d4 @abw *** empty log message ***
authored
603 #------------------------------------------------------------------------
604
a4123f8 @abw 2.04b
authored
605 sub splash_images {
606 return unless $TT_PREFIX;
911a5e3 @abw *** empty log message ***
authored
607
a4123f8 @abw 2.04b
authored
608 message(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
609
9be7d64 @abw approaching 2.04d
authored
610
611 Splash!
612 -------
613
c8d76d4 @abw *** empty log message ***
authored
614 The Splash! template library uses a number of (very) small images to
615 build user interface components. These will be installed into the
616 directory:
617
a4123f8 @abw 2.04b
authored
618 $TT_PREFIX/images
911a5e3 @abw *** empty log message ***
authored
619 EOF
620
621 if ($WIN32) {
622 # default images value for Win32 to browse via file system
a4123f8 @abw 2.04b
authored
623 $TT_IMAGES = "$TT_PREFIX/images";
624
625 message(<<EOF);
626
911a5e3 @abw *** empty log message ***
authored
627 If you want to use the Splash! library then you'll need to make sure
628 you can access these images via your browser. If you want to deliver
629 pages via a web server then you'll need to specify the URL that can be
630 use to access these images. In the general case you can accept the
631 default and access the images via the filesystem.
632
633 EOF
634 }
635 else {
a4123f8 @abw 2.04b
authored
636 message(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
637
638 If you want to use the Splash! library then you'll need to copy these
639 images, define an alias (e.g. in the httpd.conf) or create a symbolic
640 link to them so that your web server can find them. Then you'll need
641 to specify the resulting URL which can be used to retrieve them from
642 the web server.
643
644 Typical values might be '/tt2/images', '/images/tt2', '/~user/tt2/images'
645 or even something like 'http://www.yourhost.org/images/tt2'.
646
647 (NOTE: If this is too much for you to think about right now, then
648 accept the default below and read the Template::Library::Splash
649 manpage at your leisure to find out more).
650
651 EOF
911a5e3 @abw *** empty log message ***
authored
652 }
c8d76d4 @abw *** empty log message ***
authored
653
9be7d64 @abw approaching 2.04d
authored
654 $TT_IMAGES = ttprompt('URL base for TT2 images?', $TT_IMAGES || $IMAGES);
c8d76d4 @abw *** empty log message ***
authored
655 $TT_IMAGES =~ s[/$][]g; # just in case
d941238 @abw prep 2.4d
authored
656
c8d76d4 @abw *** empty log message ***
authored
657 fix_file('templates/splash/config', 'images', "$TT_IMAGES/splash");
658 }
659
660
661
a4123f8 @abw 2.04b
authored
662 #------------------------------------------------------------------------
663 # html_docs()
664 #
665 # Prompt for HTML documentation build
666 #--------------------------------------------------------------------
667
668 sub html_docs {
669 return unless $TT_PREFIX;
670
c8d76d4 @abw *** empty log message ***
authored
671 my $style = 'plain';
672 my $style_cfg = '';
673
a4123f8 @abw 2.04b
authored
674 message(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
675
9be7d64 @abw approaching 2.04d
authored
676
677 HTML Documentation
678 ------------------
679
c8d76d4 @abw *** empty log message ***
authored
680 The modules comprising the Template Toolkit contain comprehensive POD
681 documentation which can be browsed using 'perldoc' or 'man' (if your
682 system supports it). In additional, the distribution also includes a
683 set of source templates and style elements for generating the same
684 documentation in HTML format. These will be installed in the
685 directory:
686
a4123f8 @abw 2.04b
authored
687 $TT_PREFIX/docs
c8d76d4 @abw *** empty log message ***
authored
688
689 The HTML documentation can be built for you at "make install" time in
690 a plain and simple HTML format or using the Splash! library. You can
691 see examples of these different styles and browse the documentation
692 online at:
693
694 http://www.template-toolkit.org/docs/
695
696 EOF
697
698 $TT_BUILD_DOCS = (
a4123f8 @abw 2.04b
authored
699 ttprompt('Do you want to build the HTML documentation?',
c8d76d4 @abw *** empty log message ***
authored
700 $TT_BUILD_DOCS) =~ /^y/i
701 );
702
a4123f8 @abw 2.04b
authored
703 }
704
705
706 #--------------------------------------------------------------------
707 # html_docstyle()
708 #
709 # prompt for docs style: plain or splash
710 #--------------------------------------------------------------------
711
712 sub html_docstyle {
713 return unless $TT_PREFIX && $TT_BUILD_DOCS;
714
715 my $style = 'plain';
716 my $style_cfg = '';
c8d76d4 @abw *** empty log message ***
authored
717
a4123f8 @abw 2.04b
authored
718 message(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
719
ca4050f @abw prep for 2.02
authored
720 If you want to build the HTML documentation using the Splash! library
721 then you'll need to make sure you correctly defined the URL for the
722 Splash! images above. Otherwise, answer 'n' to the next question to
723 use plain HTML.
c8d76d4 @abw *** empty log message ***
authored
724
725 EOF
a4123f8 @abw 2.04b
authored
726 $TT_SPLASH_DOCS = (
727 ttprompt('Do you want to use the Splash! library?', $TT_SPLASH_DOCS) =~ /^y/i
728 );
c8d76d4 @abw *** empty log message ***
authored
729
a4123f8 @abw 2.04b
authored
730 if ($TT_SPLASH_DOCS) {
731 my $splash_style = '';
732 message(<<EOF);
ca4050f @abw prep for 2.02
authored
733
734 Which Splash! colour scheme would you like to use to build the
735 documentation? Acceptable values are:
736
737 EOF
a4123f8 @abw 2.04b
authored
738 unless ($TT_QUIET) {
ca4050f @abw prep for 2.02
authored
739 print " Name Colours\n -------------------------\n";
740 foreach my $t ('default',
741 grep { ! /^default$/ } sort keys %$SPLASH_STYLES) {
742 my $v = $SPLASH_STYLES->{ $t };
743 local $" = '/';
744 printf(" %-8s @$v\n", $t);
745 }
746 print "\n";
747
748 while (! $splash_style) {
a4123f8 @abw 2.04b
authored
749 $TT_SPLASH_THEME = ttprompt("Enter name of colour scheme: ", $TT_SPLASH_THEME);
750 message("! No such scheme\n"), $TT_SPLASH_THEME = 'default'
ca4050f @abw prep for 2.02
authored
751 unless ($splash_style = $SPLASH_STYLES->{ $TT_SPLASH_THEME });
752 }
46e4eb8 @abw * Added new colour theme called 'leon'
authored
753
754 ( $TT_SPLASH_BG, $TT_SPLASH_FG, $TT_SPLASH_BT, $TT_SPLASH_FT )
755 = @$splash_style;
756
757 # default background (unselected) text is black, fore is white
758 $TT_SPLASH_BT ||= 'black';
759 $TT_SPLASH_FT ||= 'white';
ca4050f @abw prep for 2.02
authored
760
c8d76d4 @abw *** empty log message ***
authored
761 $style = 'splash';
ca4050f @abw prep for 2.02
authored
762 $style_cfg = <<EOF;
763
764 pre_process = splash/config
765 define splash_fg = '$TT_SPLASH_FG'
766 define splash_bg = '$TT_SPLASH_BG'
46e4eb8 @abw * Added new colour theme called 'leon'
authored
767 define splash_ft = '$TT_SPLASH_FT'
768 define splash_bt = '$TT_SPLASH_BT'
ca4050f @abw prep for 2.02
authored
769 EOF
c8d76d4 @abw *** empty log message ***
authored
770 }
771 }
772
773 #--------------------------------------------------------------------
774 # write ttree config file for building docs
775 #--------------------------------------------------------------------
776
777 open(FP, "> $TT_DOCS_CFG") || die "$TT_DOCS_CFG: $!\n";
778 print FP <<EOF;
779 # This ttree configuration file is automatically generated by
780 # the Makefile.PL installation script. Feel free to edit it
781 # but be warned that re-installing the Template Toolkit will
782 # overwrite your changes.
a4123f8 @abw 2.04b
authored
783 src = $TT_PREFIX/docs/src
784 dest = $TT_PREFIX/docs/html
785 lib = $TT_PREFIX/docs/style/$style
786 lib = $TT_PREFIX/docs/lib
787 lib = $TT_PREFIX/templates
c8d76d4 @abw *** empty log message ***
authored
788 $style_cfg
789 pre_process = config
790 pre_process = header
791 post_process = footer
911a5e3 @abw *** empty log message ***
authored
792 recurse
793 verbose
c8d76d4 @abw *** empty log message ***
authored
794 EOF
795 close(FP);
a4123f8 @abw 2.04b
authored
796 }
c8d76d4 @abw *** empty log message ***
authored
797
798
a4123f8 @abw 2.04b
authored
799
800
801 #--------------------------------------------------------------------
802 # html_examples()
803 #
804 # Prompt for building examples
805 #--------------------------------------------------------------------
806
807 sub html_examples {
808 return unless $TT_PREFIX;
809
810 message(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
811
9be7d64 @abw approaching 2.04d
authored
812
813 HTML Examples
814 -------------
815
c8d76d4 @abw *** empty log message ***
authored
816 A number of examples showing use of the HTML, Splash! and PostScript
817 libraries will be installed into:
818
a4123f8 @abw 2.04b
authored
819 $TT_PREFIX/examples
c8d76d4 @abw *** empty log message ***
authored
820
821 As with the documentation, the examples are provided in template form
822 and can be automatically built into HTML pages during the "make
823 install". These pages rely on the Splash! library and expect the
824 images URL to be correctly defined for correct viewing.
825
826 EOF
827
828 $TT_EXAMPLES = (
a4123f8 @abw 2.04b
authored
829 ttprompt('Do you want to build the HTML example pages?',
c8d76d4 @abw *** empty log message ***
authored
830 $TT_EXAMPLES) =~ /^y/i
831 );
832
833 #--------------------------------------------------------------------
834 # write ttree config file for building examples
835 #--------------------------------------------------------------------
836
837 open(FP, "> $TT_EXAMPLE_CFG") || die "$TT_EXAMPLE_CFG: $!\n";
838 print FP <<EOF;
839 # This ttree configuration file is automatically generated by
840 # the Makefile.PL installation script. Feel free to edit it
841 # but be warned that re-installing the Template Toolkit will
842 # overwrite your changes.
843
a4123f8 @abw 2.04b
authored
844 src = $TT_PREFIX/examples/src
845 dest = $TT_PREFIX/examples/html
846 lib = $TT_PREFIX/examples/lib
847 lib = $TT_PREFIX/templates
ca4050f @abw prep for 2.02
authored
848 define splash_fg = '$TT_SPLASH_FG'
849 define splash_bg = '$TT_SPLASH_BG'
c8d76d4 @abw *** empty log message ***
authored
850 pre_process = config
911a5e3 @abw *** empty log message ***
authored
851 recurse
852 verbose
c8d76d4 @abw *** empty log message ***
authored
853 EOF
854
855 close(FP);
856 }
a4123f8 @abw 2.04b
authored
857
858
859 #--------------------------------------------------------------------
860 # write_defaults()
861 #
862 # write configuration defaults to file
863 #--------------------------------------------------------------------
864
865 sub write_defaults {
ca4050f @abw prep for 2.02
authored
866 open(FP, "> $DEFAULTS_FILE") || die "$DEFAULTS_FILE: $!\n";
9be7d64 @abw approaching 2.04d
authored
867 my ( $ttdbi, $ttdocs, $ttsplash, $ttex,
868 $ttlatex, $ttxs_enable, $ttxs_default )
869 = map { $_ ? 'y' : 'n' }
870 ( $TT_RUN_DBI, $TT_BUILD_DOCS, $TT_SPLASH_DOCS, $TT_EXAMPLES,
871 $TT_LATEX_ENABLE, $TT_XS_ENABLE, $TT_XS_DEFAULT );
ca4050f @abw prep for 2.02
authored
872 print FP <<EOF;
a4123f8 @abw 2.04b
authored
873 \$TT_PREFIX = '$TT_PREFIX';
f4df3b6 @abw approach v2.03
authored
874 \$TT_IMAGES = '$TT_IMAGES';
875 \$TT_RUN_DBI = '$ttdbi';
876 \$TT_BUILD_DOCS = '$ttdocs';
877 \$TT_SPLASH_DOCS = '$ttsplash';
878 \$TT_EXAMPLES = '$ttex';
879 \$TT_SPLASH_THEME = '$TT_SPLASH_THEME';
880 \$TT_LATEX_ENABLE = '$ttlatex';
881 \$TT_LATEX_PATH = '$TT_LATEX_PATH';
882 \$TT_PDFLATEX_PATH = '$TT_PDFLATEX_PATH';
883 \$TT_DVIPS_PATH = '$TT_DVIPS_PATH';
9be7d64 @abw approaching 2.04d
authored
884 \$TT_XS_ENABLE = '$ttxs_enable';
885 \$TT_XS_DEFAULT = '$ttxs_default';
a4123f8 @abw 2.04b
authored
886 \$TT_ACCEPT = '$TT_ACCEPT';
887 \$TT_QUIET = '$TT_QUIET';
9acc796 @abw post 2.03a
authored
888 1;
ca4050f @abw prep for 2.02
authored
889 EOF
890 close(FP);
c8d76d4 @abw *** empty log message ***
authored
891 }
892
48634a1 @abw *** empty log message ***
authored
893
894 #------------------------------------------------------------------------
895 # build_docs()
896 #
897 # Echo the relevant incantation so that 'make dist' regenerates the
898 # documentation from the template sources.
25a8d8e @abw *** empty log message ***
authored
899 #------------------------------------------------------------------------
eabb19e @abw *** empty log message ***
authored
900
3ebfa07 @abw Initial revision
authored
901 sub build_docs {
902 return <<EOF;
903 echo "Building documentation for version \$(VERSION)" ; \\
0b63aae @abw *** empty log message ***
authored
904 \$(PERL) bin/ttree -f ./docs/ttdist.cfg --define version=\$(VERSION) -a; \\
3ebfa07 @abw Initial revision
authored
905 EOF
906 }
907
48634a1 @abw *** empty log message ***
authored
908
82cbea8 @abw version 2.00
authored
909
910 #------------------------------------------------------------------------
867f44f @abw rc2
authored
911 # check_taf()
912 #
913 # There are some problems with Text::Autoformat with version of Perl
914 # prior to 5.6.0 not working properly with locales that use a numerical
915 # separator other than '.' (e.g. Swedish)
916 #------------------------------------------------------------------------
917
918 sub check_taf {
919 use POSIX qw( localeconv );
920 my $loc = localeconv;
921 my $dec = $loc->{ decimal_point };
922
923 yep("version $Text::Autoformat::VERSION installed");
924
925 if ($] <= 5.006 && $dec ne '.') {
926 print ' ' x 6,
927 "NOTE: tests 23 and 25 may fail under your locale, see TODO file.\n";
928 }
929 }
930
931
932 #------------------------------------------------------------------------
acff212 @abw *** empty log message ***
authored
933 # check_dom()
934 #
867f44f @abw rc2
authored
935 # XML::DOM changed from HASH to ARRAY objects somewhere between versions
936 # 1.25 and 1.27, so the latter version is an absolute necessity.
60dfe44 @abw *** empty log message ***
authored
937 #------------------------------------------------------------------------
938
939 sub check_dom {
867f44f @abw rc2
authored
940 if ($XML::DOM::VERSION < 1.27) {
941 nope("requires version 1.27 or later ($XML::DOM::VERSION installed)");
60dfe44 @abw *** empty log message ***
authored
942 }
943 else {
82cbea8 @abw version 2.00
authored
944 yep("version $XML::DOM::VERSION installed");
60dfe44 @abw *** empty log message ***
authored
945 }
946 }
947
948
acff212 @abw *** empty log message ***
authored
949 #------------------------------------------------------------------------
950 # check_rss()
951 #
952 # Version 0.8 of XML::RSS gave warnings under Perl 5.6.0 so issue an
953 # upgrade recommendation
954 #------------------------------------------------------------------------
955
60dfe44 @abw *** empty log message ***
authored
956 sub check_rss {
82cbea8 @abw version 2.00
authored
957 if ($] >= 5.006 && $XML::RSS::VERSION < 0.9) {
958 nope("requires version 0.9 or later ($XML::RSS::VERSION installed)");
60dfe44 @abw *** empty log message ***
authored
959 }
960 else {
82cbea8 @abw version 2.00
authored
961 yep("version $XML::RSS::VERSION installed");
60dfe44 @abw *** empty log message ***
authored
962 }
963 }
964
a4123f8 @abw 2.04b
authored
965
acff212 @abw *** empty log message ***
authored
966 #------------------------------------------------------------------------
967 # check_xpath()
968 #
969 # Tests fail under some of the earlier versions (e.g. 0.55) so we issue
970 # an upgrade recommendation.
971 #------------------------------------------------------------------------
60dfe44 @abw *** empty log message ***
authored
972
973 sub check_xpath {
974 if ($XML::XPath::VERSION < 1.00) {
82cbea8 @abw version 2.00
authored
975 nope("requires version 1.00 or later ($XML::XPath::VERSION installed)");
60dfe44 @abw *** empty log message ***
authored
976 }
977 else {
82cbea8 @abw version 2.00
authored
978 yep("version $XML::XPath::VERSION installed");
60dfe44 @abw *** empty log message ***
authored
979 }
980 }
981
982
983 #------------------------------------------------------------------------
48634a1 @abw *** empty log message ***
authored
984 # dbi_config()
985 #
986 # Quiz the user for options related to running the DBI tests.
987 #------------------------------------------------------------------------
988
989 sub dbi_config {
a4123f8 @abw 2.04b
authored
990 my ($dsn, $user, $pass) = ('') x 3;
48634a1 @abw *** empty log message ***
authored
991
a4123f8 @abw 2.04b
authored
992 message("[X] version $DBI::VERSION installed, configuring tests\n\n");
48634a1 @abw *** empty log message ***
authored
993
a4123f8 @abw 2.04b
authored
994 if (ttprompt("Do you want to run the DBI tests?\n" .
c8d76d4 @abw *** empty log message ***
authored
995 "It requires access to an existing test database.",
ca4050f @abw prep for 2.02
authored
996 $TT_RUN_DBI) =~ /y/i) {
48634a1 @abw *** empty log message ***
authored
997
ca4050f @abw prep for 2.02
authored
998 $TT_RUN_DBI = 1;
48634a1 @abw *** empty log message ***
authored
999 my ($driver, $dbname);
1000 my @drivers = DBI->available_drivers();
1001 local $" = ', ';
1002
30480bd @abw * Fixed bug which looked for msql or mysql DBD driver and didn't set an
authored
1003 my $default = (grep(/m.?sql/i, @drivers))[0]
1004 || $drivers[0] || '';
867f44f @abw rc2
authored
1005
a4123f8 @abw 2.04b
authored
1006 message(<<EOF);
48634a1 @abw *** empty log message ***
authored
1007
9be7d64 @abw approaching 2.04d
authored
1008 DBI Test Configuration
1009 ----------------------
1010
c8d76d4 @abw *** empty log message ***
authored
1011 Please enter the driver name for the test database.
1012 The DBD drivers installed on your system are
1013
1014 @drivers
867f44f @abw rc2
authored
1015
1016 EOF
48634a1 @abw *** empty log message ***
authored
1017
1018 while (! $driver) {
a4123f8 @abw 2.04b
authored
1019 $driver = ttprompt("Enter driver name: ", $default);
1020 message("! No such DBD driver\n"), undef $driver
48634a1 @abw *** empty log message ***
authored
1021 unless grep(/^$driver$/, @drivers);
1022 }
1023
a4123f8 @abw 2.04b
authored
1024 message(<<EOF);
c8d76d4 @abw *** empty log message ***
authored
1025
1026 Now enter the data source (DSN) for the test database.
1027 Many DBD drivers require only a database name (e.g. 'test') while
1028 others may require an alternate format or additional parameters
1029 (e.g. 'dbname=test'). Please consult your DBD documentation for
1030 further details.
1031
867f44f @abw rc2
authored
1032 EOF
1033
1034 my $dbname_eg = $driver eq 'Pg' ? 'dbname=test' : 'test';
48634a1 @abw *** empty log message ***
authored
1035 while (! $dbname) {
a4123f8 @abw 2.04b
authored
1036 $dbname = ttprompt('Database name: ', $dbname_eg);
48634a1 @abw *** empty log message ***
authored
1037 }
1038
1039 $dsn = "dbi:$driver:$dbname";
1040
a4123f8 @abw 2.04b
authored
1041 $user = ttprompt('Enter user name : ', '');
1042 $pass = ttprompt('Enter password : ', '');
48634a1 @abw *** empty log message ***
authored
1043
1044 $user = '' unless defined $user;
1045 $pass = '' unless defined $pass;
1046 }
1047 else {
ca4050f @abw prep for 2.02
authored
1048 $TT_RUN_DBI = 0;
48634a1 @abw *** empty log message ***
authored
1049 }
1050
a4123f8 @abw 2.04b
authored
1051 message("\nwriting $DBI_CONFIG_FILE\n");
48634a1 @abw *** empty log message ***
authored
1052 open(CFGFILE, ">$DBI_CONFIG_FILE") || die "$DBI_CONFIG_FILE: $!\n";
1053 print CFGFILE <<EOF;
ca4050f @abw prep for 2.02
authored
1054 \$run = $TT_RUN_DBI;
48634a1 @abw *** empty log message ***
authored
1055 \$dsn = '$dsn';
1056 \$user = '$user';
1057 \$pass = '$pass';
1058 1;
1059 EOF
1060 close(CFGFILE);
1061 }
1062
c8d76d4 @abw *** empty log message ***
authored
1063
1064
1065 #------------------------------------------------------------------------
1066 # fix_file($file, $find, $fix)
1067 #
1068 # Fixes a variable definition in a file. e.g.
d941238 @abw prep 2.4d
authored
1069 # fix_file('templates/splash/config', 'images', '/tt2/splash')
c8d76d4 @abw *** empty log message ***
authored
1070 #------------------------------------------------------------------------
1071
1072 sub fix_file {
1073 my ($file, $find, $fix) = @_;
1074 local *FP;
1075 local $/ = undef;
1076
1077 $find = quotemeta($find);
1078
1079 open(FP, "< $file") || die "$file: $!\n";
1080 my $text = <FP>;
1081 close(FP);
1082
1083 ($text =~ s/^(\s*${find}\s*=\s*)'.*?'/$1'$fix'/m)
1084 || die "$find not found in $file\n";
1085
1086 open(FP, "> $file") || die "$file: $!\n";
1087 print FP $text;
1088 close(FP);
1089 }
1090
a4123f8 @abw 2.04b
authored
1091
1092 #------------------------------------------------------------------------
9be7d64 @abw approaching 2.04d
authored
1093 # find_program($path, $prog)
f4df3b6 @abw approach v2.03
authored
1094 #
1095 # Find a program, $prog, by traversing the given directory path, $path.
1096 # Returns full path if the program is found.
1097 #
1098 # Written by Craig Barratt, Richard Tietjen add fixes for Win32.
9be7d64 @abw approaching 2.04d
authored
1099 #
1100 # abw changed name from studly caps findProgram() to find_program() :-)
a4123f8 @abw 2.04b
authored
1101 #------------------------------------------------------------------------
1102
9be7d64 @abw approaching 2.04d
authored
1103 sub find_program {
f4df3b6 @abw approach v2.03
authored
1104 my($path, $prog) = @_;
1105 my $sep = $WIN32 ? qr/;/ : qr/:/;
1106 foreach my $dir ( split($sep, $path) ) {
1107 my $file = File::Spec->catfile($dir, $prog);
1108 if ( !$WIN32 ) {
1109 return $file if ( -x $file );
1110 } else {
1111 # Windows executables end in .xxx, exe precedes .bat and .cmd
1112 foreach my $dx ( qw/exe bat cmd/ ) {
1113 return "$file.$dx" if ( -x "$file.$dx" );
1114 }
1115 }
1116 }
1117 }
a4123f8 @abw 2.04b
authored
1118
1119
1120 #------------------------------------------------------------------------
1121 # message($text)
1122 #
1123 # Print message unless quiet mode.
1124 #------------------------------------------------------------------------
1125
1126 sub message {
1127 return if $TT_QUIET;
1128 print @_;
1129 }
1130
1131
1132 #------------------------------------------------------------------------
1133 # ttprompt($message, $default)
1134 #------------------------------------------------------------------------
1135
1136 sub ttprompt {
1137 my ($msg, $def)=@_;
1138 my $ISA_TTY = -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT)) ; # Pipe?
1139 my $dispdef = defined $def ? "[$def] " : " ";
1140 $def = defined $def ? $def : "";
1141 my $ans = '';
1142 local $|=1;
1143 print "$msg $dispdef" unless $TT_QUIET;
1144 if ($TT_ACCEPT || ! $ISA_TTY) {
1145 print "$def\n" unless $TT_QUIET;
1146 }
1147 else {
1148 chomp($ans = <STDIN>);
1149 }
1150 return ($ans ne '') ? $ans : $def;
1151 }
1152
1153
1154 #------------------------------------------------------------------------
1155 # yep($text)
1156 #------------------------------------------------------------------------
1157
1158 sub yep {
1159 return if $TT_QUIET;
1160 print '[X] ', shift, "\n";
1161 }
1162
1163
1164 #------------------------------------------------------------------------
1165 # nope($text)
1166 #------------------------------------------------------------------------
1167 sub nope {
1168 return if $TT_QUIET;
1169 print '[ ] ', shift, "\n";
1170 }
Something went wrong with that request. Please try again.