Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 605 lines (463 sloc) 17.546 kb
49d1e32 Andy Wardley *** empty log message ***
authored
1 use ExtUtils::MakeMaker; # -*-perl-*-
c8d76d4 Andy Wardley *** empty log message ***
authored
2 use Cwd;
3ebfa07 Andy Wardley Initial revision
authored
3
e39913f Andy Wardley *** empty log message ***
authored
4 select STDERR;
5 $| = 1;
6 select STDOUT;
7
48634a1 Andy Wardley *** empty log message ***
authored
8 my $DBI_CONFIG_FILE = 't/dbi_test.cfg';
c8d76d4 Andy Wardley *** empty log message ***
authored
9 my $TT_INST_ROOT = '/usr/local/tt2'; # should be more platform general
10 my $TT_IMAGES = '/tt2/images'; # and honour existing installation
11 my $TT_BUILD_DOCS = 'y';
12 my $TT_SPLASH_DOCS = 'y';
13 my $TT_EXAMPLES = 'y';
14 my $TT_DOCS_CFG = 'docs/ttree.cfg';
15 my $TT_EXAMPLE_CFG = 'examples/ttree.cfg';
d52480d Andy Wardley *** empty log message ***
authored
16
48634a1 Andy Wardley *** empty log message ***
authored
17 print <<EOF;
c542301 Andy Wardley *** empty log message ***
authored
18
c8d76d4 Andy Wardley *** empty log message ***
authored
19 Template Toolkit Version 2.01
c542301 Andy Wardley *** empty log message ***
authored
20 =============================
48634a1 Andy Wardley *** empty log message ***
authored
21 EOF
22
23 #------------------------------------------------------------------------
24 # check for pre-version 2.00 installation and issue warning
25 #------------------------------------------------------------------------
26
27 eval "use Template";
28 unless ($@ or $Template::VERSION =~ /^2/) {
29 warn(<<EOF);
30
c542301 Andy Wardley *** empty log message ***
authored
31 IMPORTANT NOTE:
32 ---------------
48634a1 Andy Wardley *** empty log message ***
authored
33 You have version $Template::VERSION of the Template Toolkit installed.
25a8d8e Andy Wardley *** empty log message ***
authored
34
82cbea8 Andy Wardley version 2.00
authored
35 There are some minor incompatabilities between version 1 and 2
48634a1 Andy Wardley *** empty log message ***
authored
36 of the Template Toolkit which you should be aware of. Installing
37 this version will overwrite your version $Template::VERSION files
38 unless you take measures to install one or the other version in a
82cbea8 Andy Wardley version 2.00
authored
39 different location (i.e. perl Makefile.PL PREFIX=/other/path).
48634a1 Andy Wardley *** empty log message ***
authored
40
41 Please consult the README and Changes file for further details.
42 Most of the changes are in the more obscure features and
43 directives so hopefully you will find the upgrade process fairly
44 painless.
25a8d8e Andy Wardley *** empty log message ***
authored
45
46 EOF
48634a1 Andy Wardley *** empty log message ***
authored
47 exit unless prompt("Do you want to continue?", 'y') =~ /y/i;
48 }
49
50 #------------------------------------------------------------------------
c8d76d4 Andy Wardley *** empty log message ***
authored
51 # detect mandatory module
52 #------------------------------------------------------------------------
53
54 eval "use AppConfig";
55 if ($@ or $AppConfig::VERSION < 1.52) {
56 die(<<EOF);
57
58 The Template Toolkit requires that the AppConfig module (version 1.52
59 or later) first be installed. This is used by the 'ttree' program for
60 reading command line options and configuration files. It is available
61 from CPAN:
62
63 http://www.cpan.org/authors/Andy_Wardley/
64
65 EOF
66 }
67
68 #------------------------------------------------------------------------
48634a1 Andy Wardley *** empty log message ***
authored
69 # detect additional modules required by plugins (just for fun)
70 #------------------------------------------------------------------------
25a8d8e Andy Wardley *** empty log message ***
authored
71
48634a1 Andy Wardley *** empty log message ***
authored
72 print <<EOF;
73
82cbea8 Andy Wardley version 2.00
authored
74 The Template Toolkit includes a number of plugin modules, some of
75 which interface to external Perl modules available from CPAN. All the
76 plugins will be installed regardless so that they will automatically
77 work as and when you install the relevant modules. The tests will be
78 skipped for plugins that require external modules not currently
79 available on your system.
e39913f Andy Wardley *** empty log message ***
authored
80
81 EOF
48634a1 Andy Wardley *** empty log message ***
authored
82
867f44f Andy Wardley rc2
authored
83 foreach my $mods ( [ Text::Autoformat => \&check_taf ],
82cbea8 Andy Wardley version 2.00
authored
84 [ XML::DOM => \&check_dom ],
60dfe44 Andy Wardley *** empty log message ***
authored
85 [ XML::RSS => \&check_rss ],
86 [ XML::XPath => \&check_xpath ],
87 [ DBI => \&dbi_config ] ) {
82cbea8 Andy Wardley version 2.00
authored
88 my ($module, $code) = ref $mods ? @$mods : ($mods, 0);
60dfe44 Andy Wardley *** empty log message ***
authored
89
82cbea8 Andy Wardley version 2.00
authored
90 printf(" %-16s ", $module);
48634a1 Andy Wardley *** empty log message ***
authored
91 eval "use $module";
92 if ($@) {
82cbea8 Andy Wardley version 2.00
authored
93 nope("module not installed");
48634a1 Andy Wardley *** empty log message ***
authored
94 }
82cbea8 Andy Wardley version 2.00
authored
95 elsif ($code) {
60dfe44 Andy Wardley *** empty log message ***
authored
96 &$code;
48634a1 Andy Wardley *** empty log message ***
authored
97 }
82cbea8 Andy Wardley version 2.00
authored
98 else {
99 no strict qw( refs );
100 my $ver = ${"$module\::VERSION"};
101 yep("version $ver installed");
102 }
e39913f Andy Wardley *** empty log message ***
authored
103 }
104
c8d76d4 Andy Wardley *** empty log message ***
authored
105 #------------------------------------------------------------------------
106 # prompt for installation of optional libraries and other components
107 #------------------------------------------------------------------------
108
109 print <<EOF;
110
111 In additional to the Perl modules and POD documentation installed in
112 the usual way, the Template Toolkit distribution also contains a
113 number of optional components:
114
115 * Template libaries for basic HTML, Pod -> HTML, and PostScript
116
117 * Splash! - a stylish HTML user interface template library / widget set
118
119 * HTML documentation - distributed in template form for customisation
120
121 * Stylesheet templates to generate docs as vanilla HTML or using Splash!
122
123 * Examples - numerous examples of using the template libraries
124
125 If you want to install these optional components then you'll need to
126 specify a separate directory for them.
127
128 EOF
129
130 if (prompt('Do you want to install these components?', 'y') =~ /^y/i) {
131 print <<EOF;
132
133 You can chose any directory for the installation of the additional
134 Template Toolkit components. The proposed default, $TT_INST_ROOT,
135 assumes a Unix flavour to your operating system (suggestions for suitable
136 defaults for other platforms welcome), but something like '/home/abw/tt2'
137 or 'C:/Program Files/tt2' may be more appropriate and would be equally valid.
138
139 EOF
140 $TT_INST_ROOT = prompt('Template Toolkit installation directory',
141 $TT_INST_ROOT);
142 }
143 else {
144 $TT_INST_ROOT = '';
145 }
146
147 fix_file('lib/Template/Config.pm', '$INSTDIR', $TT_INST_ROOT);
148
149
150 #------------------------------------------------------------------------
151 # prompt for Splash! image URL
152 #------------------------------------------------------------------------
153
154 if ($TT_INST_ROOT) {
155 print <<EOF;
156
157 The Splash! template library uses a number of (very) small images to
158 build user interface components. These will be installed into the
159 directory:
160
161 $TT_INST_ROOT/images
162
163 If you want to use the Splash! library then you'll need to copy these
164 images, define an alias (e.g. in the httpd.conf) or create a symbolic
165 link to them so that your web server can find them. Then you'll need
166 to specify the resulting URL which can be used to retrieve them from
167 the web server.
168
169 Typical values might be '/tt2/images', '/images/tt2', '/~user/tt2/images'
170 or even something like 'http://www.yourhost.org/images/tt2'.
171
172 (NOTE: If this is too much for you to think about right now, then
173 accept the default below and read the Template::Library::Splash
174 manpage at your leisure to find out more).
175
176 EOF
177
178 $TT_IMAGES = prompt('URL base for TT2 images?', $TT_IMAGES);
179 $TT_IMAGES =~ s[/$][]g; # just in case
180 fix_file('templates/splash/config', 'images', "$TT_IMAGES/splash");
181 }
182
183
184
185 if ($TT_INST_ROOT) {
186 my $style = 'plain';
187 my $style_cfg = '';
188
189 #--------------------------------------------------------------------
190 # prompt for HTML documentation build
191 #--------------------------------------------------------------------
192 print <<EOF;
193
194 The modules comprising the Template Toolkit contain comprehensive POD
195 documentation which can be browsed using 'perldoc' or 'man' (if your
196 system supports it). In additional, the distribution also includes a
197 set of source templates and style elements for generating the same
198 documentation in HTML format. These will be installed in the
199 directory:
200
201 $TT_INST_ROOT/docs
202
203 The HTML documentation can be built for you at "make install" time in
204 a plain and simple HTML format or using the Splash! library. You can
205 see examples of these different styles and browse the documentation
206 online at:
207
208 http://www.template-toolkit.org/docs/
209
210 EOF
211
212 $TT_BUILD_DOCS = (
213 prompt('Do you want to build the HTML documentation?',
214 $TT_BUILD_DOCS) =~ /^y/i
215 );
216
217 #--------------------------------------------------------------------
218 # prompt for docs style: plain or splash
219 #--------------------------------------------------------------------
220
221 if ($TT_BUILD_DOCS) {
222 print <<EOF;
223
224 If you want to build the HTML documentation using then the Splash!
225 library then you'll need to make sure you correctly defined the URL
226 for the Splash! images above. Otherwise, answer 'n' to the next
227 question to use plain HTML.
228
229 EOF
230 $TT_SPLASH_DOCS = (
231 prompt('Do you want to use the Splash! library?',
232 $TT_SPLASH_DOCS) =~ /^y/i
233 );
234
235 if ($TT_SPLASH_DOCS) {
236 $style = 'splash';
237 $style_cfg = "\npre_process = splash/config";
238 }
239 }
240
241 #--------------------------------------------------------------------
242 # write ttree config file for building docs
243 #--------------------------------------------------------------------
244
245 open(FP, "> $TT_DOCS_CFG") || die "$TT_DOCS_CFG: $!\n";
246 print FP <<EOF;
247 # This ttree configuration file is automatically generated by
248 # the Makefile.PL installation script. Feel free to edit it
249 # but be warned that re-installing the Template Toolkit will
250 # overwrite your changes.
251 src = $TT_INST_ROOT/docs/src
252 dest = $TT_INST_ROOT/docs/html
253 lib = $TT_INST_ROOT/docs/style/$style
254 lib = $TT_INST_ROOT/docs/lib
255 lib = $TT_INST_ROOT/templates
256 $style_cfg
257 pre_process = config
258 pre_process = header
259 post_process = footer
260 EOF
261 close(FP);
262
263 #--------------------------------------------------------------------
264 # prompt for building examples
265 #--------------------------------------------------------------------
266
267 print <<EOF;
268
269 A number of examples showing use of the HTML, Splash! and PostScript
270 libraries will be installed into:
271
272 $TT_INST_ROOT/examples
273
274 As with the documentation, the examples are provided in template form
275 and can be automatically built into HTML pages during the "make
276 install". These pages rely on the Splash! library and expect the
277 images URL to be correctly defined for correct viewing.
278
279 EOF
280
281 $TT_EXAMPLES = (
282 prompt('Do you want to build the HTML example pages?',
283 $TT_EXAMPLES) =~ /^y/i
284 );
285
286 #--------------------------------------------------------------------
287 # write ttree config file for building examples
288 #--------------------------------------------------------------------
289
290 open(FP, "> $TT_EXAMPLE_CFG") || die "$TT_EXAMPLE_CFG: $!\n";
291 print FP <<EOF;
292 # This ttree configuration file is automatically generated by
293 # the Makefile.PL installation script. Feel free to edit it
294 # but be warned that re-installing the Template Toolkit will
295 # overwrite your changes.
296
297 src = $TT_INST_ROOT/examples/src
298 dest = $TT_INST_ROOT/examples/html
299 lib = $TT_INST_ROOT/examples/lib
300 lib = $TT_INST_ROOT/templates
301 pre_process = config
302 ignore = ^(CVS|RCS)\$
303 EOF
304
305 close(FP);
306 }
307
82cbea8 Andy Wardley version 2.00
authored
308 print "\n";
e39913f Andy Wardley *** empty log message ***
authored
309
48634a1 Andy Wardley *** empty log message ***
authored
310 #------------------------------------------------------------------------
311 # build options and write Makefile
312 #------------------------------------------------------------------------
3ebfa07 Andy Wardley Initial revision
authored
313
c8d76d4 Andy Wardley *** empty log message ***
authored
314 package MY;
315
316 sub postamble {
317 return '' unless $TT_INST_ROOT;
318 my $amble =<<'EOF';
319 tt2_install ::
320 @$(PERL) bin/tt2inst -v $(TT_INST_ROOT)
321
322 EOF
323 $amble .=<<EOF if $TT_BUILD_DOCS;
324 tt2_html_docs ::
325 \@\$(PERL) bin/ttree -v -f \$(TT_INST_ROOT)/$TT_DOCS_CFG
326 EOF
327 $amble .=<<EOF if $TT_EXAMPLES;
328 tt2_examples ::
329 \@\$(PERL) bin/ttree -v -f \$(TT_INST_ROOT)/$TT_EXAMPLE_CFG
330 EOF
331 return $amble;
332 }
333
334 sub install {
335 my $class = shift;
336 my $basic = $class->SUPER::install(@_);
337 my $add = 'tt2_install';
338 $add .= ' tt2_html_docs' if $TT_BUILD_DOCS;
339 $add .= ' tt2_examples' if $TT_EXAMPLES;
340 $basic =~ s/^(install\s+::\s+.*)$/$1 $add/m
341 if $TT_INST_ROOT;
342 $basic;
343 }
344
345 sub constants {
346 my $class = shift;
347 my $basic = $class->SUPER::constants(@_);
348 $basic = "TT_INST_ROOT = $TT_INST_ROOT\n$basic"
349 if $TT_INST_ROOT;
350 $basic;
351 }
352
353 package main;
354
25a8d8e Andy Wardley *** empty log message ***
authored
355 my %opts = (
3ebfa07 Andy Wardley Initial revision
authored
356 'NAME' => 'Template',
357 'DISTNAME' => 'Template-Toolkit',
358 'VERSION_FROM' => 'lib/Template.pm',
359 'EXE_FILES' => [ 'bin/tpage', 'bin/ttree' ],
360 'PMLIBDIRS' => [ 'lib' ],
361 'PREREQ_PM' => { 'AppConfig' => 1.52 },
362 'dist' => {
363 'COMPRESS' => 'gzip',
364 'SUFFIX' => 'gz',
c8d76d4 Andy Wardley *** empty log message ***
authored
365 # 'PREOP' => build_docs(),
3ebfa07 Andy Wardley Initial revision
authored
366 },
367 );
368
25a8d8e Andy Wardley *** empty log message ***
authored
369 if ($ExtUtils::MakeMaker::VERSION >= 5.43) {
370 $opts{ AUTHOR } = 'Andy Wardley <abw@kfs.org>';
371 $opts{ ABSTRACT } =
372 'a fast, flexible and extensible template processing system',
373 }
374
c8d76d4 Andy Wardley *** empty log message ***
authored
375
25a8d8e Andy Wardley *** empty log message ***
authored
376 WriteMakefile( %opts );
377
82cbea8 Andy Wardley version 2.00
authored
378 print <<EOF;
379
380 Configuration complete. You should now run 'make', 'make test' and then
c8d76d4 Andy Wardley *** empty log message ***
authored
381 'make install'. See the README file for further information.
382 EOF
383
384 print <<EOF if $TT_BUILD_DOCS;
385
386 Please note that the installation of the optional components and
387 building of the HTML documentation is performed at the "make install"
388 stage as the effective user at that time. This implies that this user
389 must have sufficient permission to install into the specified
390 directory and that all created directories and files will be owned by
391 them.
82cbea8 Andy Wardley version 2.00
authored
392
393 EOF
25a8d8e Andy Wardley *** empty log message ***
authored
394
48634a1 Andy Wardley *** empty log message ***
authored
395 #========================================================================
396
397
398 #------------------------------------------------------------------------
399 # build_docs()
400 #
401 # Echo the relevant incantation so that 'make dist' regenerates the
402 # documentation from the template sources.
25a8d8e Andy Wardley *** empty log message ***
authored
403 #------------------------------------------------------------------------
eabb19e Andy Wardley *** empty log message ***
authored
404
3ebfa07 Andy Wardley Initial revision
authored
405 sub build_docs {
406 return <<EOF;
407 echo "Building documentation for version \$(VERSION)" ; \\
0b63aae Andy Wardley *** empty log message ***
authored
408 \$(PERL) bin/ttree -f ./docs/ttdist.cfg --define version=\$(VERSION) -a; \\
3ebfa07 Andy Wardley Initial revision
authored
409 EOF
410 }
411
48634a1 Andy Wardley *** empty log message ***
authored
412
413 #------------------------------------------------------------------------
82cbea8 Andy Wardley version 2.00
authored
414 # yep($text)
415 # nope($text)
416 #------------------------------------------------------------------------
417
418 sub yep {
419 print '[X] ', shift, "\n";
420 }
421
422 sub nope {
423 print '[ ] ', shift, "\n";
424 }
425
426
427 #------------------------------------------------------------------------
867f44f Andy Wardley rc2
authored
428 # check_taf()
429 #
430 # There are some problems with Text::Autoformat with version of Perl
431 # prior to 5.6.0 not working properly with locales that use a numerical
432 # separator other than '.' (e.g. Swedish)
433 #------------------------------------------------------------------------
434
435 sub check_taf {
436 use POSIX qw( localeconv );
437 my $loc = localeconv;
438 my $dec = $loc->{ decimal_point };
439
440 yep("version $Text::Autoformat::VERSION installed");
441
442 if ($] <= 5.006 && $dec ne '.') {
443 print ' ' x 6,
444 "NOTE: tests 23 and 25 may fail under your locale, see TODO file.\n";
445 }
446 }
447
448
449 #------------------------------------------------------------------------
acff212 Andy Wardley *** empty log message ***
authored
450 # check_dom()
451 #
867f44f Andy Wardley rc2
authored
452 # XML::DOM changed from HASH to ARRAY objects somewhere between versions
453 # 1.25 and 1.27, so the latter version is an absolute necessity.
60dfe44 Andy Wardley *** empty log message ***
authored
454 #------------------------------------------------------------------------
455
456 sub check_dom {
867f44f Andy Wardley rc2
authored
457 if ($XML::DOM::VERSION < 1.27) {
458 nope("requires version 1.27 or later ($XML::DOM::VERSION installed)");
60dfe44 Andy Wardley *** empty log message ***
authored
459 }
460 else {
82cbea8 Andy Wardley version 2.00
authored
461 yep("version $XML::DOM::VERSION installed");
60dfe44 Andy Wardley *** empty log message ***
authored
462 }
463 }
464
465
acff212 Andy Wardley *** empty log message ***
authored
466 #------------------------------------------------------------------------
467 # check_rss()
468 #
469 # Version 0.8 of XML::RSS gave warnings under Perl 5.6.0 so issue an
470 # upgrade recommendation
471 #------------------------------------------------------------------------
472
60dfe44 Andy Wardley *** empty log message ***
authored
473 sub check_rss {
82cbea8 Andy Wardley version 2.00
authored
474 if ($] >= 5.006 && $XML::RSS::VERSION < 0.9) {
475 nope("requires version 0.9 or later ($XML::RSS::VERSION installed)");
60dfe44 Andy Wardley *** empty log message ***
authored
476 }
477 else {
82cbea8 Andy Wardley version 2.00
authored
478 yep("version $XML::RSS::VERSION installed");
60dfe44 Andy Wardley *** empty log message ***
authored
479 }
480 }
481
acff212 Andy Wardley *** empty log message ***
authored
482 #------------------------------------------------------------------------
483 # check_xpath()
484 #
485 # Tests fail under some of the earlier versions (e.g. 0.55) so we issue
486 # an upgrade recommendation.
487 #------------------------------------------------------------------------
60dfe44 Andy Wardley *** empty log message ***
authored
488
489 sub check_xpath {
490 if ($XML::XPath::VERSION < 1.00) {
82cbea8 Andy Wardley version 2.00
authored
491 nope("requires version 1.00 or later ($XML::XPath::VERSION installed)");
60dfe44 Andy Wardley *** empty log message ***
authored
492 }
493 else {
82cbea8 Andy Wardley version 2.00
authored
494 yep("version $XML::XPath::VERSION installed");
60dfe44 Andy Wardley *** empty log message ***
authored
495 }
496 }
497
498
499 #------------------------------------------------------------------------
48634a1 Andy Wardley *** empty log message ***
authored
500 # dbi_config()
501 #
502 # Quiz the user for options related to running the DBI tests.
503 #------------------------------------------------------------------------
504
505 sub dbi_config {
506 my ($dsn, $user, $pass, $run);
507 $run = 1;
508
c8d76d4 Andy Wardley *** empty log message ***
authored
509 print "[X] version $DBI::VERSION installed, configuring tests\n\n";
48634a1 Andy Wardley *** empty log message ***
authored
510
c8d76d4 Andy Wardley *** empty log message ***
authored
511 if (prompt("Do you want to run the DBI tests?\n" .
512 "It requires access to an existing test database.",
48634a1 Andy Wardley *** empty log message ***
authored
513 "y") =~ /y/i) {
514
515 my ($driver, $dbname);
516 my @drivers = DBI->available_drivers();
517 local $" = ', ';
518
519 my $default = (grep(/m.?sql/i, @drivers))[0];
867f44f Andy Wardley rc2
authored
520
521 print <<EOF;
48634a1 Andy Wardley *** empty log message ***
authored
522
c8d76d4 Andy Wardley *** empty log message ***
authored
523 Please enter the driver name for the test database.
524 The DBD drivers installed on your system are
525
526 @drivers
867f44f Andy Wardley rc2
authored
527
528 EOF
48634a1 Andy Wardley *** empty log message ***
authored
529
530 while (! $driver) {
c8d76d4 Andy Wardley *** empty log message ***
authored
531 $driver = prompt("Enter driver name: ", $default);
532 print("! No such DBD driver\n"), undef $driver
48634a1 Andy Wardley *** empty log message ***
authored
533 unless grep(/^$driver$/, @drivers);
534 }
535
867f44f Andy Wardley rc2
authored
536 print <<EOF;
c8d76d4 Andy Wardley *** empty log message ***
authored
537
538 Now enter the data source (DSN) for the test database.
539 Many DBD drivers require only a database name (e.g. 'test') while
540 others may require an alternate format or additional parameters
541 (e.g. 'dbname=test'). Please consult your DBD documentation for
542 further details.
543
867f44f Andy Wardley rc2
authored
544 EOF
545
546 my $dbname_eg = $driver eq 'Pg' ? 'dbname=test' : 'test';
48634a1 Andy Wardley *** empty log message ***
authored
547 while (! $dbname) {
c8d76d4 Andy Wardley *** empty log message ***
authored
548 $dbname = prompt('Database name: ', $dbname_eg);
48634a1 Andy Wardley *** empty log message ***
authored
549 }
550
551 $dsn = "dbi:$driver:$dbname";
552
c8d76d4 Andy Wardley *** empty log message ***
authored
553 $user = prompt('Enter user name : ', '');
554 $pass = prompt('Enter password : ', '');
48634a1 Andy Wardley *** empty log message ***
authored
555
556 $user = '' unless defined $user;
557 $pass = '' unless defined $pass;
558 }
559 else {
560 $run = 0;
561 }
562
c8d76d4 Andy Wardley *** empty log message ***
authored
563 print "\nwriting $DBI_CONFIG_FILE\n";
48634a1 Andy Wardley *** empty log message ***
authored
564 open(CFGFILE, ">$DBI_CONFIG_FILE") || die "$DBI_CONFIG_FILE: $!\n";
565 print CFGFILE <<EOF;
566 \$run = $run;
567 \$dsn = '$dsn';
568 \$user = '$user';
569 \$pass = '$pass';
570 1;
571 EOF
572 close(CFGFILE);
573 }
574
c8d76d4 Andy Wardley *** empty log message ***
authored
575
576
577 #------------------------------------------------------------------------
578 # fix_file($file, $find, $fix)
579 #
580 # Fixes a variable definition in a file. e.g.
581 # fix_file('lib/Template/Config.pm', '$INSTDIR', '/usr/local/tt2')
582 #------------------------------------------------------------------------
583
584 sub fix_file {
585 my ($file, $find, $fix) = @_;
586 local *FP;
587 local $/ = undef;
588
589 # print "\nSetting $find in $file to '$fix'\n\n";
590 $find = quotemeta($find);
591
592 open(FP, "< $file") || die "$file: $!\n";
593 my $text = <FP>;
594 close(FP);
595
596 ($text =~ s/^(\s*${find}\s*=\s*)'.*?'/$1'$fix'/m)
597 || die "$find not found in $file\n";
598
599 open(FP, "> $file") || die "$file: $!\n";
600 print FP $text;
601 close(FP);
602 }
603
604
Something went wrong with that request. Please try again.