[system] / trunk / pg / macros / problemPreserveAnswers.pl Repository:
ViewVC logotype

View of /trunk/pg/macros/problemPreserveAnswers.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5380 - (download) (as text) (annotate)
Sun Aug 19 14:58:51 2007 UTC (12 years, 3 months ago) by dpvc
File size: 2283 byte(s)
Fixes to format POD documentation better.

    1 
    2 sub _problemPreserveAnswers_init {PreserveAnswers::Init()}
    3 
    4 =head1 PreserveAnswers();
    5 
    6  ######################################################################
    7  #
    8  #  This file implements a fragile hack to overcome a problem with
    9  #  PGbasicmacros.pl, which removes special characters from student
   10  #  answers (in order to prevent EV3 from mishandling them).
   11  #
   12  #  Unfortunately, this means that "sticky" answers will lose
   13  #  those characters, which makes it very difficult to answer
   14  #  problems with more than one answer when the student wants
   15  #  to submit several times while working on later parts.
   16  #
   17  #  The real fix to to rewrite PGbasicmacros.pl to handle
   18  #  this better, but this hack will handle the situation for
   19  #  now until that can be accomplished.
   20  #
   21  #  To use this hack, simply load the file using
   22  #
   23  #    loadMacros("problemPreserveAnswers.pl");
   24  #
   25  #  at the top of your PG file.
   26  #
   27  ######################################################################
   28 
   29 =cut
   30 
   31 package PreserveAnswers;
   32 
   33 #
   34 #  Escape the specials in answers, and then
   35 #  override ENDDOCUMENT() to restore the answers
   36 #  to their original values.
   37 #
   38 sub Init {
   39   PreserveAnswers::EscapeAnswers();
   40   $PreserveAnswers::ENDDOCUMENT = \&main::ENDDOCUMENT;
   41   main::PG_restricted_eval
   42     ('sub ENDDOCUMENT {PreserveAnswers::RestoreAnswers(); &$PreserveAnswers::ENDDOCUMENT(@_)}');
   43 }
   44 
   45 #
   46 #  This is a fragile hack to prevent PG from removing the
   47 #  dollar signs in currency answers (and everything else as well).
   48 #  PGbasicmacros.pl needs to be fixed to allow this without
   49 #  having to do this terrible hack.
   50 #
   51 sub EscapeAnswers {
   52   my $original = $main::inputs_ref_orig = {%{$main::inputs_ref}};
   53   my $inputs   = $main::inputs_ref;
   54   foreach my $id (keys %{$original}) {
   55     my $value = $original->{$id};
   56     next if !defined($value) || ref($value);
   57     $value =~ s/([\\\$@\`])/EscapeHTMLchar($1)/ge;
   58     $inputs->{$id} = $value;
   59   }
   60 }
   61 
   62 sub EscapeHTMLchar {main::spf(ord(shift),"&#x%02X;")}
   63 
   64 sub RestoreAnswers {
   65   my $original = $main::inputs_ref_orig;
   66   my $inputs   = $main::inputs_ref;
   67   foreach my $id (keys %{$original}) {$inputs->{$id} = $original->{$id}}
   68 }
   69 
   70 our $ENDDOCUMENT; # holds pointer to original ENDDOCUMENT
   71 
   72 ######################################################################
   73 
   74 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9