Annotation of loncom/xml/run.pm, revision 1.21
1.2 albertel 1: package Apache::run;
1.21 ! www 2: #
! 3: # $Id: gplheader.pl,v 1.1 2001/11/29 18:19:27 www Exp $
! 4: #
! 5: # Copyright Michigan State University Board of Trustees
! 6: #
! 7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
! 8: #
! 9: # LON-CAPA is free software; you can redistribute it and/or modify
! 10: # it under the terms of the GNU General Public License as published by
! 11: # the Free Software Foundation; either version 2 of the License, or
! 12: # (at your option) any later version.
! 13: #
! 14: # LON-CAPA is distributed in the hope that it will be useful,
! 15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
! 16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 17: # GNU General Public License for more details.
! 18: #
! 19: # You should have received a copy of the GNU General Public License
! 20: # along with LON-CAPA; if not, write to the Free Software
! 21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! 22: #
! 23: # /home/httpd/html/adm/gpl.txt
! 24: #
! 25: # http://www.lon-capa.org/
! 26: #
1.1 sakharuk 27:
1.10 albertel 28: sub evaluateold {
1.4 albertel 29: my ($expression,$safeeval,$decls) = @_;
1.15 albertel 30: # print "inside2 evaluate $decls with $expression<br />\n";
1.3 albertel 31: # gerd's old method interpolates unset vars
1.5 albertel 32: # $safeeval->reval('return qq('.$expression.');');
33: unless (defined $expression) { return ''; }
1.7 albertel 34: my $result = '';
35: $@='';
1.9 sakharuk 36: $safeeval->reval('$_=q|'.$expression.'|;');
1.7 albertel 37: if ($@ eq '') {
1.9 sakharuk 38: $safeeval->reval('{'.$decls.'$_=~s/(\$[A-Za-z]\w*)/(defined(eval($1))?eval($1):$1)/ge;}');
1.7 albertel 39: if ($@ eq '') {
40: $result = $safeeval->reval('return $_;');
41: } else {
1.10 albertel 42: &Apache::lonxml::error("substitution on:$expression:with:$decls:caused");
1.7 albertel 43: }
44: } else {
45: &Apache::lonxml::error("defining:$expression:caused");
46: }
47: if ($@ ne '') {&Apache::lonxml::error($@);}
1.10 albertel 48: return $result
49: }
50:
1.11 albertel 51: $Apache::run::EVALUATE_STRING=<<'ENDEVALUATE';
52: my %oldexpressions=();
53: while (!$oldexpressions{$_}) {
54: $oldexpressions{$_}=1;
1.13 www 55: $_ =~s/((?:\$|\&)(?:[\#|\$]*[A-Za-z][\w]*|\{[A-Za-z][\w]*\}))([\[\{][^\$\&\]\}]+[\]\}])*?(\([^\$\&\)]+\))*?(?=[^\[\{\(]|$)/eval(defined(eval($1.$2))?eval('$1.$2.$3'):'$1.$2.$3')/seg;
1.11 albertel 56: }
57: ENDEVALUATE
58:
1.10 albertel 59: sub evaluate {
60: my ($expression,$safeeval,$decls) = @_;
61: unless (defined $expression) { return ''; }
1.16 albertel 62: if (!$Apache::lonxml::evaluate) { return $expression; }
1.10 albertel 63: my $result = '';
64: $@='';
1.11 albertel 65: $safeeval->reval('{'.$decls.';$_=<<\'EXPRESSION\';'."\n".$expression.
66: "\n".'EXPRESSION'."\n".$EVALUATE_STRING.'}');
67: # $safeeval->reval('{'.$decls.';<< &evaluate(q|'.$expression.'|);}');
1.10 albertel 68: if ($@ eq '') {
69: $result = $safeeval->reval('return $_;');
1.13 www 70: chomp $result;
1.10 albertel 71: } else {
72: &Apache::lonxml::error("substitution on:$expression:with:$decls:caused $@");
73: }
1.7 albertel 74: return $result
1.2 albertel 75: }
76:
77: sub run {
1.18 albertel 78: my ($code,$safeeval,$hideerrors) = @_;
1.3 albertel 79: # print "inside run\n";
1.7 albertel 80: $@='';
1.14 albertel 81: my (@result)=$safeeval->reval($code);
1.18 albertel 82: if ($@ ne '' && !$hideerrors) {
83: &Apache::lonxml::error(":$code:caused");
84: &Apache::lonxml::error($@);
1.7 albertel 85: }
1.14 albertel 86: if ( $#result < '1') {
87: return $result[0];
88: } else {
89: &Apache::lonxml::debug("<b>Got lots results</b>:$#result:");
90: return (@result);
91: }
1.2 albertel 92: }
93:
1.19 albertel 94: sub dump {
95: my ($target,$safeeval)=@_;
96: my $dump='';
97: foreach my $symname (sort keys %{$safeeval->varglob('main::')}) {
98: if (($symname!~/^\_/) && ($symname!~/\:$/)) {
1.20 albertel 99: if ($safeeval->reval('defined($'.$symname.')')) {
1.19 albertel 100: $dump.='$'.$symname.'='.$safeeval->reval('$'.$symname)."\n";
101: }
102: if ($safeeval->reval('defined @'.$symname)) {
103: $dump.='@'.$symname.'=('.
104: $safeeval->reval('join(",",@'.$symname.')').")\n";
105: }
106: if ($safeeval->reval('defined %'.$symname)) {
107: $dump.='%'.$symname.'=(';
108: $dump.=$safeeval->reval('join(",",map { $_."=>".$'.
109: $symname.'{$_} } sort keys %'.
110: $symname.')').")\n";
111: }
112: }
113: }
114: $dump.='';
115: return $dump;
116: }
117:
1.2 albertel 118: 1;
119: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>