Diff for /loncom/xml/run.pm between versions 1.30 and 1.43

version 1.30, 2002/05/24 16:48:50 version 1.43, 2004/01/29 18:46:25
Line 37  $Apache::run::EVALUATE_STRING=<<'ENDEVAL Line 37  $Apache::run::EVALUATE_STRING=<<'ENDEVAL
 ENDEVALUATE  ENDEVALUATE
   
 sub evaluate {  sub evaluate {
   my ($expression,$safeeval,$decls) = @_;      my ($expression,$safeeval,$decls) = @_;
   unless (defined($expression)) { return ''; }      unless (defined($expression)) { return ''; }
   if (!$Apache::lonxml::evaluate) { return $expression; }      if ($Apache::lonxml::evaluate < 1) { return $expression; }
   my $result = '';      my $result = '';
   $@='';      $@='';
   if ($Apache::lonxml::request) {      $Apache::run::timeout=0;
     $Apache::lonxml::request->hard_timeout("Apache::run::run, evaluation $code");      $main::SIG{'ALRM'} = sub {
   }   $Apache::run::timeout=1;
   $safeeval->reval('{'.$decls.';$_=<<\'EXPRESSION\';'."\n".$expression.   die("timeout");
    "\n".'EXPRESSION'."\n".$EVALUATE_STRING.'}');      };
   if ($Apache::lonxml::request) { $Apache::lonxml::request->kill_timeout; }      my $innererror;
 #  $safeeval->reval('{'.$decls.';<< &evaluate(q|'.$expression.'|);}');      eval {
   my $error=$@;   alarm($Apache::lonnet::perlvar{'lonScriptTimeout'});
   if ($@ eq '') {   $safeeval->reval('{'.$decls.';$_=<<\'EXPRESSION\';'."\n".$expression.
     $result = $safeeval->reval('return $_;');   "\n".'EXPRESSION'."\n".$EVALUATE_STRING.'}');
     chomp $result;   $innererror=$@;
   } else {   alarm(0);
     &Apache::lonxml::error('substitution on <pre>'.$expression.      };
    '</pre> with <pre>'.$decls.      my $error=$@;
    '</pre> caused <pre>'.$error);      if ($error eq '' && $innererror eq '' && !$Apache::run::timeout) {
   }     $result = $safeeval->reval('return $_;');
   return $result   chomp $result;
       } else {
    if ($Apache::run::timeout) {
       $error = 'Code ran too long. It ran for more than '.
    $Apache::lonnet::perlvar{'lonScriptTimeout'}.' seconds';
    }
    &Apache::lonxml::error('substitution on <pre>'.
          &HTML::Entities::encode($expression).
          '</pre> with <pre>'.
          &HTML::Entities::encode($decls).
          '</pre> caused <pre>'.
          &HTML::Entities::encode($error).' '.
          &HTML::Entities::encode($innererror).
          '</pre>');
       }
       return $result
 }  }
   
 sub run {  sub run {
   my ($code,$safeeval,$hideerrors) = @_;      my ($code,$safeeval,$hideerrors) = @_;
 #  print "inside run\n";      my @result;
   $@='';      $@='';
   if ($Apache::lonxml::request) {      $Apache::run::timeout=0;
     $Apache::lonxml::request->hard_timeout("Apache::run::run, evaluation $code");      $main::SIG{'ALRM'} = sub {
   }   $Apache::run::timeout=1;
   my (@result)=$safeeval->reval($code);   die("timeout");
   if ($Apache::lonxml::request) { $Apache::lonxml::request->kill_timeout; }      };
   my $error=$@;      my $innererror;
   if ($error ne '' && !$hideerrors) {      eval {
     &Apache::lonxml::error('<pre>'.&HTML::Entities::encode($error).   alarm($Apache::lonnet::perlvar{'lonScriptTimeout'});
    '</pre> occured while running <pre>'.   @result=$safeeval->reval($code);
    &HTML::Entities::encode($code).'</pre>');   $innererror=$@;
   }   alarm(0);
   if ( $#result < '1') {      };
     return $result[0];      my $error=$@;
   } else {      if (($Apache::run::timeout || $error ne '' || $innererror ne '') && !$hideerrors) {
     &Apache::lonxml::debug("<b>Got lots results</b>:$#result:");   if ($Apache::run::timeout) {
     return (@result);      $error = 'Code ran too long. It ran for more than '.
   }   $Apache::lonnet::perlvar{'lonScriptTimeout'}.' seconds';
    }
    my $errormsg='<pre>'.&HTML::Entities::encode($error).' '.
       &HTML::Entities::encode($innererror).
       '</pre> occured while running <pre>';
    $code=&HTML::Entities::encode($code);
    if ($innererror=~/line (\d+)/) {
       my $linenumber=$1;
       my @code=split("\n",$code);
       $code[$linenumber-1]='<b><font color="red">'.
    $code[$linenumber-1].'</font></b>';
       $code=join("\n",@code);
    }
    &Apache::lonxml::error($errormsg.$code.'</pre>');
       }
       if ( $#result < '1') {
    return $result[0];
       } else {
    &Apache::lonxml::debug("<b>Got lots results</b>:$#result:");
    return (@result);
       }
 }  }
   
 sub dump {  sub dump {
   my ($target,$safeeval)=@_;      my ($target,$safeeval)=@_;
   my $dump='';      my $dump='';
   foreach my $symname (sort keys %{$safeeval->varglob('main::')}) {      foreach my $symname (sort keys %{$safeeval->varglob('main::')}) {
     if (($symname!~/^\_/) && ($symname!~/\:$/)) {   if (($symname!~/^\_/) && ($symname!~/\:$/)) {
       my $line;      my $line;
       if ($safeeval->reval('defined($'.$symname.')')) {      if ($safeeval->reval('defined($'.$symname.')')) {
  $line='$'.$symname.'='.$safeeval->reval('$'.$symname);   $line='$'.$symname.'='.$safeeval->reval('$'.$symname);
       }      }
       if ($safeeval->reval('defined(@'.$symname.')')) {      if ($safeeval->reval('defined(@'.$symname.')')) {
  $line='@'.$symname.'=('.   $line='@'.$symname.'=('.
   $safeeval->reval('join(",",@'.$symname.')').")";      $safeeval->reval('join(",",@'.$symname.')').")";
       }      }
       if ($safeeval->reval('defined(%'.$symname.')')) {      if ($safeeval->reval('defined(%'.$symname.')')) {
  $line='%'.$symname.'=(';   $line='%'.$symname.'=(';
  $line.=$safeeval->reval('join(",",map { $_."=>".$'.   $line.=$safeeval->reval('join(",",map { $_."=>".$'.
  $symname.'{$_} } sort keys %'.   $symname.'{$_} } sort keys %'.
  $symname.')').")"   $symname.')').")"
       }      }
       if ($line ne '') { $dump.=&HTML::Entities::encode($line)."<br />\n"; }      if ($line ne '') {$dump.=&HTML::Entities::encode($line)."<br />";}
    }
     }      }
   }      $dump.='';
   $dump.='';      return $dump;
   return $dump;  
 }  }
   
 1;  1;

Removed from v.1.30  
changed lines
  Added in v.1.43


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