From: dpvc v. a. <we...@ma...> - 2005-08-25 03:39:31
|
Log Message: ----------- Fixed problem with Context's not properly initializing themselves with the WW environment parameters (like zeroLevelTol and useBaseTenLog). The copy method and the method that did an initialized copy used to be separate routines, but that turned out to be unnecessary, so they have now been merged (copy always tries to initialize the WW values when it can, and when the copied context doesn't already have them). The reason this is complicated is that a number contexts are set up before the global.conf data is available, so these can't be initialized with the WW values. Also, these default contexts are stored in the persistant processes, and we don't want to leave possibly course-specific values lying around in them, so whenever a context is selected, it is copied from the standard version and the WW parameters are inserted into it. The problem author can only modify the copy, not the original, so this is OK with mod_perl. The context's copy method now always tries to initialize (we used to have to call initCoopy to get a copy that has the WW parameters inserted). That turned out to cause trouble with code that handled contexts without the usual Context() command. Modified Files: -------------- pg/lib/Parser: Context.pm pg/lib/Value: Context.pm WeBWorK.pm Revision Data ------------- Index: Context.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Parser/Context.pm,v retrieving revision 1.13 retrieving revision 1.14 diff -Llib/Parser/Context.pm -Llib/Parser/Context.pm -u -r1.13 -r1.14 --- lib/Parser/Context.pm +++ lib/Parser/Context.pm @@ -16,7 +16,7 @@ # sub new { my $self = shift; my $class = ref($self) || $self; - my $context = $Value::defaultContext->initCopy; + my $context = $Value::defaultContext->copy; bless $context, $class; $context->{parser} = {%{$Parser::class}}; push(@{$context->{data}{values}},'parser'); @@ -105,7 +105,7 @@ $contextTable->{current} = $context; $Value::context = \$contextTable->{current}; } elsif (!defined($contextTable->{current})) { - $contextTable->{current} = $Parser::Context::Default::numericContext->initCopy; + $contextTable->{current} = $Parser::Context::Default::numericContext->copy; $Value::context = \$contextTable->{current}; } return $contextTable->{current}; @@ -121,7 +121,7 @@ return $context if $context; $context = $Parser::Context::Default::context{$name}; return unless $context; - return $context->initCopy; + return $context->copy; } # Index: WeBWorK.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/WeBWorK.pm,v retrieving revision 1.10 retrieving revision 1.11 diff -Llib/Value/WeBWorK.pm -Llib/Value/WeBWorK.pm -u -r1.10 -r1.11 --- lib/Value/WeBWorK.pm +++ lib/Value/WeBWorK.pm @@ -80,15 +80,16 @@ useBaseTenLog ); -sub Parser::Context::initCopy { +sub Parser::Context::copy { my $self = shift; - my $context = $self->copy(@_); + my $context = Value::Context::copy($self,@_); + return $context unless $Parser::installed; # only do WW initialization after parser is fully loaded return $context if $context->{WW} && scalar(keys %{$context->{WW}}) > 0; - $context->{WW} = {}; push @{$context->{data}{values}}, 'WW'; + my $envir = eval('\\%main::envir'); + return $context unless $envir && scalar(keys(%{$envir})) > 0; + my $ww = $context->{WW} = {}; push @{$context->{data}{values}}, 'WW'; return $context if $Value::_no_WeBWorK_; # hack for command-line debugging - return $context unless $Parser::installed; # only do WW initialization after parser is fully loaded - foreach my $x (@wwEvalFields) {$context->{WW}{$x} = eval('$main::envir{'.$x.'}');} - my $ww = $context->{WW}; + foreach my $x (@wwEvalFields) {$context->{WW}{$x} = $envir->{$x}} $context->flags->set( tolerance => $ww->{numRelPercentTolDefault} / 100, zeroLevel => $ww->{numZeroLevelDefault}, Index: Context.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/Context.pm,v retrieving revision 1.7 retrieving revision 1.8 diff -Llib/Value/Context.pm -Llib/Value/Context.pm -u -r1.7 -r1.8 --- lib/Value/Context.pm +++ lib/Value/Context.pm @@ -81,11 +81,6 @@ return $context; } -# -# Make a copy with additional initialization -# (defined in subclasses) -# -sub initCopy {shift->copy(@_)} # # Make stringify produce TeX or regular strings |