Log Message:
-----------
Added the ability to put class-specific answer-checker defaults into
the Context object. For example,
Context("Vector")->{cmpDefaults}{Vector}{promotePoints} = 1;
would make all Vector answer checkers include promotePoints=>1
automatically. (Note however that if a subclass of Vector is used, it
will not get this defaults, since its class name would be different.
Perhaps something more sophisticated will be needed in the future.)
Modified Files:
--------------
pg/lib/Value:
AnswerChecker.pm
Revision Data
-------------
Index: AnswerChecker.pm
===================================================================
RCS file: /webwork/cvs/system/pg/lib/Value/AnswerChecker.pm,v
retrieving revision 1.60
retrieving revision 1.61
diff -Llib/Value/AnswerChecker.pm -Llib/Value/AnswerChecker.pm -u -r1.60 -r1.61
--- lib/Value/AnswerChecker.pm
+++ lib/Value/AnswerChecker.pm
@@ -14,6 +14,12 @@
package Value;
#
+# Context can add default values to the answer checkers by class;
+#
+$Value::defaultContext->{cmpDefaults} = {};
+
+
+#
# Create an answer checker for the given type of object
#
@@ -30,16 +36,17 @@
my $ans = new AnswerEvaluator;
my $correct = protectHTML($self->{correct_ans});
$correct = $self->correct_ans unless defined($correct);
+ $self->{context} = $$Value::context unless defined($self->{context});
$ans->ans_hash(
type => "Value (".$self->class.")",
correct_ans => $correct,
correct_value => $self,
$self->cmp_defaults(@_),
+ %{$self->{context}{cmpDefaults}{$self->class} || {}}, # context-specified defaults
@_
);
$ans->install_evaluator(sub {$ans = shift; $ans->{correct_value}->cmp_parse($ans)});
$ans->install_pre_filter('erase') if $self->{ans_name}; # don't do blank check if answer_array
- $self->{context} = $$Value::context unless defined($self->{context});
return $ans;
}
|