File:
[LON-CAPA] /
loncom /
xml /
run.pm
Revision
1.11:
download - view:
text,
annotated -
select for diffs
Wed Nov 15 15:29:33 2000 UTC (23 years, 9 months ago) by
albertel
Branches:
MAIN
CVS tags:
HEAD
- fixed Apache::run::evaluate so it actually does work
- it also now properly Quotes the expression so we shouldn't have anymore
problems with quoting
1: package Apache::run;
2:
3: sub evaluateold {
4: my ($expression,$safeeval,$decls) = @_;
5: # print "inside2 evaluate $decls with $expression<br>\n";
6: # gerd's old method interpolates unset vars
7: # $safeeval->reval('return qq('.$expression.');');
8: unless (defined $expression) { return ''; }
9: my $result = '';
10: $@='';
11: $safeeval->reval('$_=q|'.$expression.'|;');
12: if ($@ eq '') {
13: $safeeval->reval('{'.$decls.'$_=~s/(\$[A-Za-z]\w*)/(defined(eval($1))?eval($1):$1)/ge;}');
14: if ($@ eq '') {
15: $result = $safeeval->reval('return $_;');
16: } else {
17: &Apache::lonxml::error("substitution on:$expression:with:$decls:caused");
18: }
19: } else {
20: &Apache::lonxml::error("defining:$expression:caused");
21: }
22: if ($@ ne '') {&Apache::lonxml::error($@);}
23: return $result
24: }
25:
26: $Apache::run::EVALUATE_STRING=<<'ENDEVALUATE';
27: my %oldexpressions=();
28: while (!$oldexpressions{$_}) {
29: $oldexpressions{$_}=1;
30: $_ =~s/((?:\$|\&)(?:[\#|\$]*[A-Za-z][\w]*|\{[A-Za-z][\w]*\}))([\[|\{][\w\'\"]+[\]\}])*?(\([\w\'\"]+\))*?(?=[^\[\{\(]|$)/eval(defined(eval($1.$2))?eval('$1.$2.$3'):'$1.$2.$3')/seg;
31: }
32: ENDEVALUATE
33:
34: sub evaluate {
35: my ($expression,$safeeval,$decls) = @_;
36: unless (defined $expression) { return ''; }
37: my $result = '';
38: $@='';
39: print $decls
40: $safeeval->reval('{'.$decls.';$_=<<\'EXPRESSION\';'."\n".$expression.
41: "\n".'EXPRESSION'."\n".$EVALUATE_STRING.'}');
42: # $safeeval->reval('{'.$decls.';<< &evaluate(q|'.$expression.'|);}');
43: if ($@ eq '') {
44: $result = $safeeval->reval('return $_;');
45: } else {
46: &Apache::lonxml::error("substitution on:$expression:with:$decls:caused $@");
47: }
48: return $result
49: }
50:
51: sub run {
52: my ($code,$safeeval) = @_;
53: # print "inside run\n";
54: $@='';
55: my $result=$safeeval->reval($code);
56: if ($@ ne '') {
57: &Apache::lonxml::error(":$code:caused");
58: &Apache::lonxml::error($@);
59: }
60: return $result;
61: }
62:
63: 1;
64: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>