Annotation of loncom/xml/run.pm, revision 1.25

1.2       albertel    1: package Apache::run;
1.21      www         2: #
1.25    ! matthew     3: # $Id: run.pm,v 1.24 2002/03/29 18:21:00 albertel Exp $
1.21      www         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.11      albertel   28: $Apache::run::EVALUATE_STRING=<<'ENDEVALUATE';  
1.24      albertel   29:   my %_LONCAPA_INTERNAL_oldexpressions=();
                     30:   my $i=0;
                     31:   while (!$_LONCAPA_INTERNAL_oldexpressions{$_}) {
                     32:     $_LONCAPA_INTERNAL_oldexpressions{$_}=1;
1.13      www        33:     $_ =~s/((?:\$|\&)(?:[\#|\$]*[A-Za-z][\w]*|\{[A-Za-z][\w]*\}))([\[\{][^\$\&\]\}]+[\]\}])*?(\([^\$\&\)]+\))*?(?=[^\[\{\(]|$)/eval(defined(eval($1.$2))?eval('$1.$2.$3'):'$1.$2.$3')/seg;
1.24      albertel   34:     if ($i++ > 10 ) { last; }
1.11      albertel   35:   }
                     36: ENDEVALUATE
                     37: 
1.10      albertel   38: sub evaluate {
                     39:   my ($expression,$safeeval,$decls) = @_;
1.22      albertel   40:   unless (defined($expression)) { return ''; }
1.16      albertel   41:   if (!$Apache::lonxml::evaluate) { return $expression; }
1.10      albertel   42:   my $result = '';
                     43:   $@='';
1.11      albertel   44:   $safeeval->reval('{'.$decls.';$_=<<\'EXPRESSION\';'."\n".$expression.
                     45: 		   "\n".'EXPRESSION'."\n".$EVALUATE_STRING.'}');
                     46: #  $safeeval->reval('{'.$decls.';<< &evaluate(q|'.$expression.'|);}');
1.10      albertel   47:   if ($@ eq '') {
                     48:     $result = $safeeval->reval('return $_;');
1.13      www        49:     chomp $result;
1.10      albertel   50:   } else {
                     51:     &Apache::lonxml::error("substitution on:$expression:with:$decls:caused $@");
                     52:   }  
1.7       albertel   53:   return $result
1.2       albertel   54: }
                     55: 
                     56: sub run {
1.18      albertel   57:   my ($code,$safeeval,$hideerrors) = @_;
1.3       albertel   58: #  print "inside run\n";
1.7       albertel   59:   $@='';
1.14      albertel   60:   my (@result)=$safeeval->reval($code);
1.18      albertel   61:   if ($@ ne '' && !$hideerrors) {
1.25    ! matthew    62:     # Put in newline to make display of code easier to read.
        !            63:     &Apache::lonxml::error(":$@: occured while running :\n$code");
1.7       albertel   64:   }
1.14      albertel   65:   if ( $#result < '1') {
                     66:     return $result[0];
                     67:   } else {
                     68:     &Apache::lonxml::debug("<b>Got lots results</b>:$#result:");
                     69:     return (@result);
                     70:   }
1.2       albertel   71: }
                     72: 
1.19      albertel   73: sub dump {
                     74:   my ($target,$safeeval)=@_;
                     75:   my $dump='';
                     76:   foreach my $symname (sort keys %{$safeeval->varglob('main::')}) {
                     77:     if (($symname!~/^\_/) && ($symname!~/\:$/)) {
1.20      albertel   78:       if ($safeeval->reval('defined($'.$symname.')')) {
1.19      albertel   79: 	$dump.='$'.$symname.'='.$safeeval->reval('$'.$symname)."\n";
                     80:       }	
1.22      albertel   81:       if ($safeeval->reval('defined(@'.$symname.')')) {
1.19      albertel   82: 	$dump.='@'.$symname.'=('.
                     83: 	  $safeeval->reval('join(",",@'.$symname.')').")\n";
                     84:       }
1.22      albertel   85:       if ($safeeval->reval('defined(%'.$symname.')')) {
1.19      albertel   86: 	$dump.='%'.$symname.'=(';
                     87: 	$dump.=$safeeval->reval('join(",",map { $_."=>".$'.
                     88: 				$symname.'{$_} } sort keys %'.
                     89: 				$symname.')').")\n";
                     90:       }
                     91:     }
                     92:   }
                     93:   $dump.='';
                     94:   return $dump;
                     95: }
                     96: 
1.2       albertel   97: 1;
                     98: __END__;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>