--- loncom/homework/caparesponse/caparesponse.pm 2011/06/08 01:39:32 1.247 +++ loncom/homework/caparesponse/caparesponse.pm 2011/06/08 20:38:50 1.248 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # caparesponse definition # -# $Id: caparesponse.pm,v 1.247 2011/06/08 01:39:32 www Exp $ +# $Id: caparesponse.pm,v 1.248 2011/06/08 20:38:50 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -280,6 +280,8 @@ sub start_numericalresponse { $token,40). &Apache::loncommon::help_open_topic('Formula_Response_Sampling'); } + $result.=&Apache::edit::text_arg('Pre-Processor Subroutine:','preprocess', + $token,10); $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); } elsif ($target eq 'modified') { my $constructtag; @@ -287,11 +289,11 @@ sub start_numericalresponse { $constructtag=&Apache::edit::get_new_args($token,$parstack, $safeeval,'answer', 'incorrect','unit', - 'format'); + 'format','preprocess'); } elsif ($token->[1] eq 'formularesponse') { $constructtag=&Apache::edit::get_new_args($token,$parstack, $safeeval,'answer', - 'samples'); + 'samples','preproces'); } if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); @@ -1148,12 +1150,14 @@ sub start_stringresponse { ['re','Regular Expression']],$token); $result.=&Apache::edit::text_arg('String to display for answer:', 'answerdisplay',$token); + $result.=&Apache::edit::text_arg('Pre-Processor Subroutine:','preprocess', + $token,10); $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); } elsif ($target eq 'modified') { my $constructtag; $constructtag=&Apache::edit::get_new_args($token,$parstack, $safeeval,'answer', - 'type','answerdisplay'); + 'type','answerdisplay','preprocess'); if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); $result.=&Apache::edit::handle_insert(); @@ -1213,12 +1217,17 @@ sub end_stringresponse { # $answer=$token->[2]->{'answer'}; # } ${$safeeval->varglob('LONCAPA::response')}=$response; + my $preprocess=&Apache::lonxml::get_param('preprocess',$parstack,$safeeval); + $preprocess=~s/^\&//; + if (defined($preprocess)) { + &Apache::run::run('$LONCAPA::response=&'.$preprocess.'($LONCAPA::response);',$safeeval); + } $result = &Apache::run::run('if ($LONCAPA::response=~m'.$answer.') { return 1; } else { return 0; }',$safeeval); &Apache::lonxml::debug("current $response"); &Apache::lonxml::debug("current $answer"); $ad = ($result) ? 'APPROX_ANS' : 'INCORRECT'; } else { - my @args = ('type'); + my @args = ('type','preprocess'); my $args_ref = &setup_capa_args($safeeval,$parstack, \@args,$response); if ($$args_ref{'type'} eq '') {