From: Martin Mares Date: Thu, 2 Oct 2008 19:27:19 +0000 (+0200) Subject: Replace all outputs by an overridable call to `out'. X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=7d0bd29651f02f022412e5920abfa7b1228c68be;p=temple.git Replace all outputs by an overridable call to `out'. --- diff --git a/UCW/Temple.pm b/UCW/Temple.pm index 572bc25..bafe91d 100644 --- a/UCW/Temple.pm +++ b/UCW/Temple.pm @@ -8,10 +8,20 @@ use strict; use warnings; no strict 'vars'; +require Exporter; +our $VERSION = 1.0; +our @ISA = qw(Exporter); +our @EXPORT = qw(out); +our @EXPORT_OK = qw(); + use IO::File; our @cond; +sub out { + $T::out_func->(@_); +} + sub get_nested($$$) { my ($r,$left,$right) = @_; pos $$r = pos($$r)-1; @@ -73,7 +83,7 @@ sub eval_func($$) { # print "Cond stack: @cond\n"; } else { my $res = eval_if_ok("$f($a)"); - print $res if defined $res; + out $res if defined $res; } } @@ -82,16 +92,16 @@ sub parse_string($) { pos $t = 0; for(;;) { if ($t =~ /\G([^\@]+)/cgs) { - print $1 if $cond[0] > 0; + out $1 if $cond[0] > 0; } elsif ($t =~ /\G\@\s*\n/cgs) { # @ at end of line is ignored and eats the end of line } elsif ($t =~ /\G\@#[^\n]*\n/cgs) { # a comment, which is ignored } elsif ($t =~ /\G\@\@/cgs) { - print "\@"; + out "\@"; } elsif ($t =~ /\G\@{/cgs) { my $x = get_nested(\$t, "{", "}"); - print eval_if_ok($x); + out eval_if_ok($x); } elsif ($t =~ /\G\@\[/cgs) { my $x = get_nested(\$t, '\[', '\]'); $x =~ s/^\[//; @@ -104,7 +114,7 @@ sub parse_string($) { } elsif ($t =~ /\G\@(\w+)([^\n]*)\n/cgs) { eval_func($1, "($2)"); } elsif ($t =~ /\G\@(\$\w+)/cgs) { - print eval_if_ok($1); + out eval_if_ok($1); } elsif ($t =~ /\G(\@[^\n]*)/cgs) { die "Unknown control sequence $1"; } elsif ($t =~ /\G$/cgs) { @@ -151,7 +161,10 @@ sub process_string($) { package T; +import UCW::Temple; + our $temp; +our $out_func = sub { print @_; }; sub include { my $fn = shift @_;