[LON-CAPA-cvs] cvs: loncom /homework default_homework.lcpm /homework/caparesponse caparesponse.pm

www www@source.lon-capa.org
Wed, 08 Jun 2011 01:39:32 -0000


www		Wed Jun  8 01:39:32 2011 EDT

  Modified files:              
    /loncom/homework	default_homework.lcpm 
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  Bug #2020: work on preprocessor
  
  
Index: loncom/homework/default_homework.lcpm
diff -u loncom/homework/default_homework.lcpm:1.156 loncom/homework/default_homework.lcpm:1.157
--- loncom/homework/default_homework.lcpm:1.156	Tue Jun  7 22:07:09 2011
+++ loncom/homework/default_homework.lcpm	Wed Jun  8 01:39:28 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
 #
-# $Id: default_homework.lcpm,v 1.156 2011/06/07 22:07:09 www Exp $
+# $Id: default_homework.lcpm,v 1.157 2011/06/08 01:39:28 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -270,7 +270,10 @@
     my $type = $LONCAPA::CAPAresponse_args{'type'};
     my $answerunit=$LONCAPA::CAPAresponse_args{'unit'};
     &LONCAPA_INTERNAL_DEBUG("Got type :$type: answer unit :$answerunit:\n");
-    
+   
+    my $preprocess=$LONCAPA::CAPAresponse_args{'preprocess'};
+    $preprocess=~s/^\&//;
+
     my $num_input_lines =
 	scalar(@{$LONCAPA::CAPAresponse_answer->{'answers'}});
     
@@ -319,7 +322,7 @@
         } else {
            ($part1,$part2)=($responses->[0][-1]=~ /^([\d\.\,\s\$]*(?:(?:[xX\*]10[\^\*]*|[eE]*)[\+\-]*\d*)*(?:^|\S)\d+)([\$\s\w\^\*\/\(\)\+\-]*[^\d\.\s\,][\$\s\w\^\*\/\(\)\+\-]*)$/);
         }
-        if ($part1 && $part2) {
+        if (defined($part1) && defined($part2)) {
 	    $responses->[0][-1]=$part1;
 	    $unit=&capa_formula_fix($part2);
             &LONCAPA_INTERNAL_DEBUG("Found unit :$unit:");
@@ -329,7 +332,15 @@
     $unit=~s/\s//;
     my $error;
     foreach my $response (@$responses) {
-       foreach my $element (@$response) {	
+       foreach my $element (@$response) {
+          # See if we have preprocessor
+          if ($preprocess=~/\S/) {
+             if (defined(&$preprocess)) {
+                no strict 'refs';
+                $element=&$preprocess($element);
+                use strict 'refs';
+             }
+          }
           if (($type eq 'float') || (($type eq '') && ($unit ne ''))) {
               $element =~ s/\s//g;
           }
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.246 loncom/homework/caparesponse/caparesponse.pm:1.247
--- loncom/homework/caparesponse/caparesponse.pm:1.246	Thu Feb 24 23:09:32 2011
+++ loncom/homework/caparesponse/caparesponse.pm	Wed Jun  8 01:39:32 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.246 2011/02/24 23:09:32 raeburn Exp $
+# $Id: caparesponse.pm,v 1.247 2011/06/08 01:39:32 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -402,7 +402,7 @@
 
 sub check_submission {
     my ($response,$partid,$id,$tag,$parstack,$safeeval,$ignore_sig)=@_;
-    my @args = ('type','tol','sig','format','unit','calc','samples');
+    my @args = ('type','tol','sig','format','unit','calc','samples','preprocess');
     my $args_ref = &setup_capa_args($safeeval,$parstack,\@args,$response);
 
     my $hideunit=