Annotation of loncom/xml/run.pm, revision 1.10
1.2 albertel 1: package Apache::run;
1.1 sakharuk 2:
1.10 ! albertel 3: sub evaluateold {
1.4 albertel 4: my ($expression,$safeeval,$decls) = @_;
1.6 albertel 5: # print "inside2 evaluate $decls with $expression<br>\n";
1.3 albertel 6: # gerd's old method interpolates unset vars
1.5 albertel 7: # $safeeval->reval('return qq('.$expression.');');
8: unless (defined $expression) { return ''; }
1.7 albertel 9: my $result = '';
10: $@='';
1.9 sakharuk 11: $safeeval->reval('$_=q|'.$expression.'|;');
1.7 albertel 12: if ($@ eq '') {
1.9 sakharuk 13: $safeeval->reval('{'.$decls.'$_=~s/(\$[A-Za-z]\w*)/(defined(eval($1))?eval($1):$1)/ge;}');
1.7 albertel 14: if ($@ eq '') {
15: $result = $safeeval->reval('return $_;');
16: } else {
1.10 ! albertel 17: &Apache::lonxml::error("substitution on:$expression:with:$decls:caused");
1.7 albertel 18: }
19: } else {
20: &Apache::lonxml::error("defining:$expression:caused");
21: }
22: if ($@ ne '') {&Apache::lonxml::error($@);}
1.10 ! albertel 23: return $result
! 24: }
! 25:
! 26: sub evaluate {
! 27: my ($expression,$safeeval,$decls) = @_;
! 28: unless (defined $expression) { return ''; }
! 29: my $result = '';
! 30: $@='';
! 31: $safeeval->reval('{'.$decls.';&evaluate(q|'.$expression.'|);}');
! 32: if ($@ eq '') {
! 33: $result = $safeeval->reval('return $_;');
! 34: } else {
! 35: &Apache::lonxml::error("substitution on:$expression:with:$decls:caused $@");
! 36: }
1.7 albertel 37: return $result
1.2 albertel 38: }
39:
40: sub run {
41: my ($code,$safeeval) = @_;
1.3 albertel 42: # print "inside run\n";
1.7 albertel 43: $@='';
44: my $result=$safeeval->reval($code);
45: if ($@ ne '') {
46: &Apache::lonxml::error(":$code:caused");
47: &Apache::lonxml::error($@);
48: }
49: return $result;
1.2 albertel 50: }
51:
52: 1;
53: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>