| … | |
… | |
| 65 | sub cmp { |
65 | sub cmp { |
| 66 | my $self = shift; |
66 | my $self = shift; |
| 67 | my $ans = new AnswerEvaluator; |
67 | my $ans = new AnswerEvaluator; |
| 68 | my $correct = protectHTML($self->{correct_ans}); |
68 | my $correct = protectHTML($self->{correct_ans}); |
| 69 | $correct = $self->correct_ans unless defined($correct); |
69 | $correct = $self->correct_ans unless defined($correct); |
| 70 | $self->{context} = $$Value::context unless defined($self->{context}); |
70 | $self->{context} = Value->context unless defined($self->{context}); |
| 71 | $ans->ans_hash( |
71 | $ans->ans_hash( |
| 72 | type => "Value (".$self->class.")", |
72 | type => "Value (".$self->class.")", |
| 73 | correct_ans => $correct, |
73 | correct_ans => $correct, |
| 74 | correct_value => $self, |
74 | correct_value => $self, |
| 75 | $self->cmp_defaults(@_), |
75 | $self->cmp_defaults(@_), |
| … | |
… | |
| 98 | sub cmp_parse { |
98 | sub cmp_parse { |
| 99 | my $self = shift; my $ans = shift; |
99 | my $self = shift; my $ans = shift; |
| 100 | # |
100 | # |
| 101 | # Do some setup |
101 | # Do some setup |
| 102 | # |
102 | # |
| 103 | my $current = $$Value::context; # save it for later |
103 | my $current = Value->context; # save it for later |
| 104 | my $context = $ans->{correct_value}{context} || $current; |
104 | my $context = $ans->{correct_value}{context} || $current; |
| 105 | Parser::Context->current(undef,$context); # change to correct answser's context |
105 | Parser::Context->current(undef,$context); # change to correct answser's context |
| 106 | my $flags = contextSet($context,$self->cmp_contextFlags($ans)); # save old context flags |
106 | my $flags = contextSet($context,$self->cmp_contextFlags($ans)); # save old context flags |
| 107 | my $inputs = $self->getPG('$inputs_ref',{action=>""}); |
107 | my $inputs = $self->getPG('$inputs_ref',{action=>""}); |
| 108 | $ans->{isPreview} = $inputs->{previewAnswers} || ($inputs->{action} =~ m/^Preview/); |
108 | $ans->{isPreview} = $inputs->{previewAnswers} || ($inputs->{action} =~ m/^Preview/); |
| … | |
… | |
| 293 | # (To be used when overriding Parser classes that need |
293 | # (To be used when overriding Parser classes that need |
| 294 | # to report errors to the student but can't do it in |
294 | # to report errors to the student but can't do it in |
| 295 | # the overridden == since errors are trapped.) |
295 | # the overridden == since errors are trapped.) |
| 296 | # |
296 | # |
| 297 | sub cmp_Message { |
297 | sub cmp_Message { |
| 298 | my $message = shift; |
298 | my $message = shift; my $context = Value->context; |
| 299 | $message = [$message,@_] if scalar(@_) > 0; |
299 | $message = [$message,@_] if scalar(@_) > 0; |
| 300 | $$Value::context->setError($message,'',undef,undef,$CMP_MESSAGE); |
300 | $context->setError($message,'',undef,undef,$CMP_MESSAGE); |
| 301 | $message = $$Value::context->{error}{message}; |
301 | $message = $context->{error}{message}; |
| 302 | die $message . traceback() if $$Value::context->flags('showTraceback'); |
302 | die $message . traceback() if $context->flags('showTraceback'); |
| 303 | die $message . getCaller(); |
303 | die $message . getCaller(); |
| 304 | } |
304 | } |
| 305 | |
305 | |
| 306 | # |
306 | # |
| 307 | # filled in by sub-classes |
307 | # filled in by sub-classes |