]> mj.ucw.cz Git - temple.git/commitdiff
Replace all outputs by an overridable call to `out'.
authorMartin Mares <mj@ucw.cz>
Thu, 2 Oct 2008 19:27:19 +0000 (21:27 +0200)
committerMartin Mares <mj@ucw.cz>
Thu, 2 Oct 2008 19:27:19 +0000 (21:27 +0200)
UCW/Temple.pm

index 572bc2547597872a289ffdaad68ebafb4fddecf6..bafe91d6bf65593be184178c806414b1ea02bbf1 100644 (file)
@@ -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 @_;