I noticed an issue while hardening my code for a problem. Despite using the LimitedNumeric context, a student entering a character instead of an expected number for an answer, would view a "PG warning message" of "The evaluated answer is not an answer hash."
This issue could be traced to the use of the "withPostFilter" flag in the custom answer checker. Below is a MWE that exemplifies the issue. The call of ANS on line 11 triggers the "answer hash" alert, however the call of ANS on line 12 (sans "withPostFilter") behaves as expected.
Unfortunately, I need to use the wtihPostFilter flag in my sig fig code
to properly display input in the "Entered" and "Answer Preview"
columns. In principle, I could encapsulate triggering statements such as line 16 in the MWE with a regular expression in a conditional or attempt to use perl's Scalar::Util::looks_like_number()
, but such approaches appear redundant and against the spirit of the LimitedNumeric context.
I would appreciate any suggestions.
DOCUMENT();
loadMacros("PGstandard.pl", "PGML.pl");
Context("LimitedNumeric");
$corr=Real(1);
BEGIN_PGML
Enter the number 1: [___]
END_PGML
ANS($corr->cmp->withPostFilter(
#ANS($corr->cmp(
sub {
$ansHash=shift;
$sval = $ansHash->{student_value};
Real($sval); #To trip the answer hash warning
return $ansHash;
}#end sub
) #end cmp
); #end ANS()
ENDDOCUMENT();