From 7d0bd29651f02f022412e5920abfa7b1228c68be Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Thu, 2 Oct 2008 21:27:19 +0200 Subject: [PATCH] Replace all outputs by an overridable call to `out'. --- UCW/Temple.pm | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) 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 @_; -- 2.39.5