3 # Reads one or more template files and runs it through Text::Template
5 # It is assumed that this scripts is called with -Mconfigdata, a module
6 # that holds configuration data in %config
12 # We actually expect to get the following hash tables from configdata:
18 # We just do a minimal test to see that we got what we expected.
19 # $config{target} must exist as an absolute minimum.
20 die "You must run this script with -Mconfigdata\n" if !exists($config{target});
22 # Helper functions for the templates #################################
24 # It might be practical to quotify some strings and have them protected
25 # from possible harm. These functions primarly quote things that might
26 # be interpreted wrongly by a perl eval.
29 # This adds quotes (") around the given string, and escapes any $, @, \,
30 # " and ' by prepending a \ to them.
33 $s =~ s/([\$\@\\"'])/\\$1/g;
38 # For each defined element in LIST (i.e. elements that aren't undef), have
39 # it quotified with 'quotofy1'
50 # Error reporter #####################################################
52 # The error reporter uses %lines to figure out exactly which file the
53 # error happened and at what line. Not that the line number may be
54 # the start of a perl snippet rather than the exact line where it
55 # happened. Nothing we can do about that here.
60 my $filename = "<STDIN>";
62 foreach (sort keys %lines) {
63 $filename = $lines{$_};
64 last if ($_ > $args{lineno});
67 print STDERR $args{error}," in $filename, fragment starting at line ",$args{lineno}-$deducelines;
71 # Template reading ###################################################
73 # Read in all the templates into $text, while keeping track of each
74 # file and its size in lines, to try to help report errors with the
75 # correct file name and line number.
77 my $prev_linecount = 0;
80 ? join("", map { my $x = my $y = Text::Template::_load_text($_);
81 my $linecount = $x =~ tr/\n//;
82 $prev_linecount = ($linecount += $prev_linecount);
83 $lines{$linecount} = $_;
87 # Engage! ############################################################
89 # Load the full template (combination of files) into Text::Template
90 # and fill it up with our data. Output goes directly to STDOUT
92 my $template = Text::Template->new(TYPE => 'STRING', SOURCE => $text );
93 $template->fill_in(OUTPUT => \*STDOUT,
94 HASH => { config => \%config,
96 quotify1 => \"ify1,
97 quotify_l => \"ify_l },
98 DELIMITERS => [ "{-", "-}" ],