Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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