-#!/usr/bin/perl
+#!/usr/bin/perl -CSA
# A really simple template engine
# (c) 2004 Martin Mares <mj@ucw.cz>
use strict;
use warnings;
+use lib '.';
+use Getopt::Long;
use UCW::Temple;
-if (@ARGV == 1) {
- UCW::Temple::process_file($ARGV[0]);
-} elsif (@ARGV == 2) {
+my $out;
+my @execs = ();
+
+GetOptions('out|o=s' => \$out, 'exec|e=s' => \@execs) or die "Usage: temple [-o <out>] [-e <string>] <in> ...";
+if (defined $out) {
close STDOUT;
- open STDOUT, ">$ARGV[1]" or die "Cannot open $ARGV[1]: $!";
- UCW::Temple::process_file($ARGV[0]);
-} else {
- die "Usage: temple <in> [<out>]";
+ open STDOUT, '>:utf8', $out or die "Cannot open $out: $!";
+}
+if (!@ARGV) { push @ARGV, "-"; }
+UCW::Temple::start();
+foreach (@execs) {
+ UCW::Temple::parse_string($_, "-e");
+}
+foreach (@ARGV) {
+ UCW::Temple::parse_file($_);
}
+UCW::Temple::finish();