[interchange-cvs] interchange - heins modified lib/Vend/Interpolate.pm

interchange-core@interchange.redhat.com interchange-core@interchange.redhat.com
Thu Oct 18 05:41:02 2001


User:      heins
Date:      2001-10-18 09:40:44 GMT
Modified:  lib/Vend Interpolate.pm
Log:
	* SafeTrap changes
	* Add new accessor methods for [item-tag-foo ...], which now is enabled
	  for array lists. Can call any ITL tag with

	  	[PREFIX-tag-itltag parm=value] container [/PREFIX-tag-itltag]

	  Container text is always sent as $opt->{body}, but would be
	  ignored if tag is not a container tag.

Revision  Changes    Path
2.21      +45 -3     interchange/lib/Vend/Interpolate.pm


rev 2.21, prev_rev 2.20
Index: Interpolate.pm
===================================================================
RCS file: /anon_cvs/repository/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.20
retrieving revision 2.21
diff -u -r2.20 -r2.21
--- Interpolate.pm	2001/10/13 13:48:47	2.20
+++ Interpolate.pm	2001/10/18 09:40:44	2.21
@@ -1,6 +1,6 @@
 # Vend::Interpolate - Interpret Interchange tags
 # 
-# $Id: Interpolate.pm,v 2.20 2001/10/13 13:48:47 mheins Exp $
+# $Id: Interpolate.pm,v 2.21 2001/10/18 09:40:44 mheins Exp $
 #
 # Copyright (C) 1996-2001 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -27,7 +27,7 @@
 require Exporter;
 @ISA = qw(Exporter);
 
-$VERSION = substr(q$Revision: 2.20 $, 10);
+$VERSION = substr(q$Revision: 2.21 $, 10);
 
 @EXPORT = qw (
 
@@ -35,6 +35,10 @@
 interpolate_html
 subtotal
 tag_data
+$Tag
+$CGI
+$Session
+$Values
 
 );
 
@@ -161,6 +165,7 @@
 use vars qw/%Filter %Ship_handler $Safe_data/;
 
 $ready_safe = new Safe;
+$ready_safe->trap(qw/:base_io/);
 $ready_safe->untrap(qw/sort ftfile/);
 
 sub reset_calc {
@@ -175,6 +180,7 @@
 		$ready_safe = new Safe $pkg;
 		$ready_safe->share_from('MVSAFE', ['$safe']);
 #::logDebug("new safe made=$ready_safe->{Root}");
+		$ready_safe->trap(@{$Global::SafeTrap});
 		$ready_safe->untrap(@{$Global::SafeUntrap});
 		no strict 'refs';
 		$Document   = new Vend::Document;
@@ -1417,6 +1423,7 @@
 	RUNSAFE: {
 		last RUNSAFE if defined $status;
 		last RUNSAFE if $status = ($noop && $op);
+		$ready_safe->trap(@{$Global::SafeTrap});
 		$ready_safe->untrap(@{$Global::SafeUntrap});
 		$status = $ready_safe->reval($op)
 			unless ($@ or $status);
@@ -3008,8 +3015,12 @@
 		$value = filter_value($opt->{filter}, $value, $var);
 		$CGI::values{$var} = $value unless $opt->{keep};
 	}
-    return $value unless $opt->{hide};
-    return '';
+
+    return '' if $opt->{hide};
+
+	$value =~ s/</&lt;/g
+		unless $opt->{enable_html};
+    return $value;
 }
 
 # Returns the text of a user entered field named VAR.
@@ -3032,6 +3043,8 @@
 	}
 
 	my $val = $CGI::values{$var} || $::Values->{$var} || return undef;
+	$val =~ s/</&lt;/g unless $opt->{enable_html};
+	$val =~ s/\[/&#91;/g unless $opt->{enable_itl};
 	
 	if($opt->{file_contents}) {
 		return '' if ! defined $CGI::file{$var};
@@ -3387,6 +3400,7 @@
 # Returns the text of a user entered field named VAR.
 sub tag_value {
     my($var,$opt) = @_;
+#::logDebug("called value args=" . ::uneval(\@_));
     my($value);
 
 	local($^W) = 0;
@@ -3404,6 +3418,8 @@
 	$::Scratch->{$var} = $value if $opt->{scratch};
 	return '' if $opt->{hide};
     return $opt->{default} if ! $value and defined $opt->{default};
+	$value =~ s/</&lt;/g
+		unless $opt->{enable_html};
     return $value;
 }
 
@@ -4701,8 +4717,26 @@
 	return pull_if($body);
 }
 
+sub tag_object {
+	my ($count, $item, $hash, $opt, $body) = @_;
+	my $param = delete $hash->{param}
+		or return undef;
+	my $method;
+	my $out = '';
+	eval {
+		if(not $method = delete $hash->{method}) {
+			$out = $item->{$param}->();
+		}
+		else {
+			$out = $item->{$param}->$method();
+		}
+	};
+	return $out;
+}
+
 my %Dispatch_hash = (
 	address => \&tag_address,
+	address => \&tag_object,
 );
 
 sub find_matching_else {
@@ -4748,7 +4782,7 @@
 	$tag =~ tr/-/_/;
 	my $full = lc "$Orig_prefix-tag-$tag";
 	$full =~ tr/-/_/;
-
+#::logDebug("tag_dispatch: tag=$tag count=$count chunk=$chunk");
 	my $attrseq = [];
 	my $attrhash = {};
 	my $eaten;
@@ -4765,6 +4799,12 @@
 	if(defined $Dispatch_hash{$tag}) {
 		$out = $Dispatch_hash{$tag}->($count, $item, $hash, $attrhash, $this_tag);
 	}
+	else {
+		$attrhash->{body} = $this_tag unless defined $attrhash->{body};
+#::logDebug("calling do_tag tag=$tag this_tag=$this_tag attrhash=" . ::uneval($attrhash));
+		$Tag ||= new Vend::Tags;
+		$out = $Tag->$tag($attrhash);
+	}
 	return $out . $chunk;
 }
 
@@ -4870,6 +4910,8 @@
 							check_change($1,$3,undef,$2)
 											?	pull_if($4)
 											:	pull_else($4)!ige;
+		$run =~ s#$B$QR{_tag}($Some$E[-_]tag[-_]\1\])#
+						tag_dispatch($1,$count, $row, $ary, $2)#ige;
 		$run =~ s#$B$QR{_calc}$E$QR{'/_calc'}#tag_calc($1)#ige;
 		$run =~ s#$B$QR{_exec}$E$QR{'/_exec'}#
 					init_calc() if ! $Vend::Calc_initialized;