--- loncom/homework/default_homework.lcpm 2011/06/07 22:07:09 1.156 +++ loncom/homework/default_homework.lcpm 2011/06/08 20:38:47 1.158 @@ -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.158 2011/06/08 20:38:47 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -270,7 +270,10 @@ sub caparesponse_check_list { 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 @@ sub caparesponse_check_list { } 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 @@ sub caparesponse_check_list { $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,$unit); + use strict 'refs'; + } + } if (($type eq 'float') || (($type eq '') && ($unit ne ''))) { $element =~ s/\s//g; } @@ -403,6 +414,17 @@ sub caparesponse_check_list { } } } + # See if we have preprocessor + &LONCAPA_INTERNAL_DEBUG("Ordered preprocessor $preprocess"); + if ($preprocess=~/\S/) { + if (defined(&$preprocess)) { + no strict 'refs'; + $response->[$j]=&$preprocess($response->[$j]); + use strict 'refs'; + &LONCAPA_INTERNAL_DEBUG("Ordered processed: $response->[$j]"); + } + } + my ($award,$msg) = &caparesponse_check($answer->[$j], $response->[$j]); if ($type eq 'cs' || $type eq 'ci') { @@ -441,6 +463,17 @@ sub caparesponse_check_list { } } } + # See if we have preprocessor + &LONCAPA_INTERNAL_DEBUG("Unordered preprocessor $preprocess"); + if ($preprocess=~/\S/) { + if (defined(&$preprocess)) { + no strict 'refs'; + $response->[$j]=&$preprocess($response->[$j]); + use strict 'refs'; + &LONCAPA_INTERNAL_DEBUG("Unordered processed: $response->[$j]"); + } + } + my ($award,$msg) = &caparesponse_check($answer->[$j], $response->[$j]); if ($type eq 'cs' || $type eq 'ci') {