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

Diff of /trunk/pg/macros/PG.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1253 Revision 1266
74 74
75# Private variables for the PG.pl file. 75# Private variables for the PG.pl file.
76 76
77my ($STRINGforOUTPUT, $STRINGforHEADER_TEXT, @PG_ANSWERS, @PG_UNLABELED_ANSWERS); 77my ($STRINGforOUTPUT, $STRINGforHEADER_TEXT, @PG_ANSWERS, @PG_UNLABELED_ANSWERS);
78my %PG_ANSWERS_HASH ; 78my %PG_ANSWERS_HASH ;
79# my variables are unreliable if two DOCUMENTS were to be called before and ENDDOCUMENT
80# there could be conflicts. As I understand the behavior of the Apache child
81# this cannot occur -- a child finishes with one request before obtaining the next
79 82
80# DOCUMENT must come early in every .pg file, before any answers or text are 83# DOCUMENT must come early in every .pg file, before any answers or text are
81# defined. It initializes the variables. 84# defined. It initializes the variables.
82# It can appear only once. 85# It can appear only once.
83 86
116 %PG_ANSWERS_HASH = (); 119 %PG_ANSWERS_HASH = ();
117 # FIXME: We are initializing these variables into both Safe::Root1 (the cached safe compartment) 120 # FIXME: We are initializing these variables into both Safe::Root1 (the cached safe compartment)
118 # and Safe::Root2 (the current one) 121 # and Safe::Root2 (the current one)
119 # There is a good chance they won't be properly updated in one or the other of these compartments. 122 # There is a good chance they won't be properly updated in one or the other of these compartments.
120 123
121 @main::PG_ANSWER_ENTRY_ORDER = (); 124# @main::PG_ANSWER_ENTRY_ORDER = ();
122 $main::ANSWER_PREFIX = 'AnSwEr'; 125# $main::ANSWER_PREFIX = 'AnSwEr';
123 %main::PG_FLAGS=(); #global flags 126# %main::PG_FLAGS=(); #global flags
124 $main::showPartialCorrectAnswers = 0 unless defined($main::showPartialCorrectAnswers ); 127# $main::showPartialCorrectAnswers = 0 unless defined($main::showPartialCorrectAnswers );
125 $main::showHint = 1 unless defined($main::showHint); 128# $main::showHint = 1 unless defined($main::showHint);
126 $main::solutionExists =0; 129# $main::solutionExists =0;
127 $main::hintExists =0; 130# $main::hintExists =0;
128 %main::gifs_created = (); 131# %main::gifs_created = ();
129 eval(q! 132 eval(q!
130 @main::PG_ANSWER_ENTRY_ORDER = (); 133 @main::PG_ANSWER_ENTRY_ORDER = ();
131 $main::ANSWER_PREFIX = 'AnSwEr'; 134 $main::ANSWER_PREFIX = 'AnSwEr';
132 %main::PG_FLAGS=(); #global flags 135 %main::PG_FLAGS=(); #global flags
133 $main::showPartialCorrectAnswers = 0 unless defined($main::showPartialCorrectAnswers ); 136 $main::showPartialCorrectAnswers = 0 unless defined($main::showPartialCorrectAnswers );
134 $main::showHint = 1 unless defined($main::showHint); 137 $main::showHint = 1 unless defined($main::showHint);
135 $main::solutionExists =0; 138 $main::solutionExists =0;
136 $main::hintExists =0; 139 $main::hintExists =0;
137 %main::gifs_created = (); 140 %main::gifs_created = ();
138 !); 141 !);
139 die "The environment variable envir has not been defined" unless defined(%main::envir); 142# warn eval(q! "PG.pl: The envir variable $main::{envir} is".join(" ",%main::envir)!);
140 143 my $rh_envir = eval(q!\%main::envir!);
144 my %envir = %$rh_envir;
145 no strict;
141 foreach my $var ( keys %main::envir ) { 146 foreach my $var (keys %envir) {
142 eval("\$main::$var =\$main::envir{'$var'}"); 147 eval(q!$main::!.$var.q! = $main::envir{!.$var.q!}! ); #whew!! makes sure $var is interpolated but $main:: is evaluated at run time.
148 # warn eval(q! "var $var is defined ". $main::!.$var);
143 warn "Problem defining ", q{\$main::$var}, " while inititializing the PG problem: $@" if $@; 149 warn "Problem defining ", q{\$main::}.$var, " while initializing the PG problem: $@" if $@;
144 } 150 }
151 use strict;
152
153
154
145 eval(q! 155 eval(q!
146 @main::submittedAnswers = @{$main::refSubmittedAnswers} if defined($main::refSubmittedAnswers); 156 @main::submittedAnswers = @{$main::refSubmittedAnswers} if defined($main::refSubmittedAnswers);
147 $main::PG_original_problemSeed = $main::problemSeed; 157 $main::PG_original_problemSeed = $main::problemSeed;
148 $main::PG_random_generator = new PGrandom($main::problemSeed) || die "Can't create random number generator."; 158 $main::PG_random_generator = new PGrandom($main::problemSeed) || die "Can't create random number generator.";
149 $main::ans_rule_count = 0; # counts questions 159 $main::ans_rule_count = 0; # counts questions
150 160
151 # end unpacking of environment variables. 161 # end unpacking of environment variables.
152 $main::QUIZ_PREFIX = '' unless defined($main::QUIZ_PREFIX) 162 $main::QUIZ_PREFIX = '' unless defined($main::QUIZ_PREFIX)
153 163
154 !); 164 !);
155 @main::submittedAnswers = @{$main::refSubmittedAnswers} if defined($main::refSubmittedAnswers); 165# @main::submittedAnswers = @{$main::refSubmittedAnswers} if defined($main::refSubmittedAnswers);
156 $main::PG_original_problemSeed = $main::problemSeed; 166# $main::PG_original_problemSeed = $main::problemSeed;
157 $main::PG_random_generator = new PGrandom($main::problemSeed) || die "Can't create random number generator."; 167# $main::PG_random_generator = new PGrandom($main::problemSeed) || die "Can't create random number generator.";
158 $main::ans_rule_count = 0; # counts questions 168# $main::ans_rule_count = 0; # counts questions
159 169
160 # end unpacking of environment variables. 170 # end unpacking of environment variables.
161 $main::QUIZ_PREFIX = '' unless defined($main::QUIZ_PREFIX) 171# $main::QUIZ_PREFIX = '' unless defined($main::QUIZ_PREFIX)
162 172
163} 173}
164 174
175sub inc_ans_rule_count {
176 eval(q!++$main::ans_rule_count!); # evalute at runtime to get correct main::
177}
165# HEADER_TEXT is for material which is destined to be placed in the header of the html problem -- such 178# HEADER_TEXT is for material which is destined to be placed in the header of the html problem -- such
166# as javaScript code. 179# as javaScript code.
167 180
168=head2 HEADER_TEXT() 181=head2 HEADER_TEXT()
169 182
350 } 363 }
351 $index++; 364 $index++;
352 } 365 }
353 366
354 $STRINGforOUTPUT .="\n"; 367 $STRINGforOUTPUT .="\n";
355 ##eval q{ #make sure that "main" points to the current safe compartment by evaluating these lines. 368 eval q{ #make sure that "main" points to the current safe compartment by evaluating these lines.
356 $main::PG_FLAGS{'showPartialCorrectAnswers'} = $main::showPartialCorrectAnswers; 369 $main::PG_FLAGS{'showPartialCorrectAnswers'} = $main::showPartialCorrectAnswers;
357 $main::PG_FLAGS{'recordSubmittedAnswers'} = $main::recordSubmittedAnswers; 370 $main::PG_FLAGS{'recordSubmittedAnswers'} = $main::recordSubmittedAnswers;
358 $main::PG_FLAGS{'refreshCachedImages'} = $main::refreshCachedImages; 371 $main::PG_FLAGS{'refreshCachedImages'} = $main::refreshCachedImages;
359 $main::PG_FLAGS{'hintExists'} = $main::hintExists; 372 $main::PG_FLAGS{'hintExists'} = $main::hintExists;
360 $main::PG_FLAGS{'showHintLimit'} = $main::showHint; 373 $main::PG_FLAGS{'showHintLimit'} = $main::showHint;
384 } elsif (defined(&std_problem_grader)) { 397 } elsif (defined(&std_problem_grader)) {
385 $main::PG_FLAGS{PROBLEM_GRADER_TO_USE} = \&std_problem_grader; # defined in PGanswermacros.pl 398 $main::PG_FLAGS{PROBLEM_GRADER_TO_USE} = \&std_problem_grader; # defined in PGanswermacros.pl
386 } else { 399 } else {
387 # PGtranslator will install its default problem grader 400 # PGtranslator will install its default problem grader
388 } 401 }
389 ##}; 402
390 warn "ERROR: The problem grader is not a subroutine" unless ref( $main::PG_FLAGS{PROBLEM_GRADER_TO_USE}) eq 'CODE' 403 warn "ERROR: The problem grader is not a subroutine" unless ref( $main::PG_FLAGS{PROBLEM_GRADER_TO_USE}) eq 'CODE'
391 or $main::PG_FLAGS{PROBLEM_GRADER_TO_USE} = 'std_problem_grader' 404 or $main::PG_FLAGS{PROBLEM_GRADER_TO_USE} = 'std_problem_grader'
392 or $main::PG_FLAGS{PROBLEM_GRADER_TO_USE} = 'avg_problem_grader'; 405 or $main::PG_FLAGS{PROBLEM_GRADER_TO_USE} = 'avg_problem_grader';
393 # return results 406 # return results
407 };
394 (\$STRINGforOUTPUT, \$STRINGforHEADER_TEXT,\%PG_ANSWERS_HASH,\%main::PG_FLAGS); 408 (\$STRINGforOUTPUT, \$STRINGforHEADER_TEXT,\%PG_ANSWERS_HASH,eval(q!\%main::PG_FLAGS!));
395} 409}
396 410
397 411
398 412
399=head2 INITIALIZE_PG() 413=head2 INITIALIZE_PG()

Legend:
Removed from v.1253  
changed lines
  Added in v.1266

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9