![]() ![]() | ![]() |
- added code to check for and report errors
1: package Apache::run; 2: 3: sub evaluate { 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('$_=\''.$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("substituion 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: sub run { 27: my ($code,$safeeval) = @_; 28: # print "inside run\n"; 29: $@=''; 30: my $result=$safeeval->reval($code); 31: if ($@ ne '') { 32: &Apache::lonxml::error(":$code:caused"); 33: &Apache::lonxml::error($@); 34: } 35: return $result; 36: } 37: 38: 1; 39: __END__;