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

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

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

Revision 1304 Revision 1305
225 my $macro_file_name = $fileName; 225 my $macro_file_name = $fileName;
226 $macro_file_name =~s/\.pl//; # trim off the extension 226 $macro_file_name =~s/\.pl//; # trim off the extension
227 $macro_file_name =~s/\.pg//; # sometimes the extension is .pg (e.g. CAPA files) 227 $macro_file_name =~s/\.pg//; # sometimes the extension is .pg (e.g. CAPA files)
228 my $init_subroutine_name = "_${macro_file_name}_init"; 228 my $init_subroutine_name = "_${macro_file_name}_init";
229 229
230 #no strict;
231 ############################################################################### 230 ###############################################################################
232 # For some reason the "no stict" which works on webwork-db doesn't work on 231 # For some reason the "no stict" which works on webwork-db doesn't work on
233 # webwork. For this reason the constuction &{$init_subroutine_name} 232 # webwork. For this reason the constuction &{$init_subroutine_name}
234 # was abandoned and replaced by eval. This is considerably more dangerous 233 # was abandoned and replaced by eval. This is considerably more dangerous
235 # since one could hide something nasty in a file name. 234 # since one could hide something nasty in a file name.
236 # Keep an eye on this ??? 235 # Keep an eye on this ???
237 # webwork-db used perl 5.6.1 and webwork used perl 5.6.0 It seems 236 # webwork-db used perl 5.6.1 and webwork used perl 5.6.0
238 # unlikely that this was the problem. Otherwise all files seemed to 237
239 # be the same. 238 ###############################################################################
239 # compile initialization subroutine. (5.6.0 version)
240
240 241
241 # local($temp::rf_init_subroutine);
242 # eval qq{ \$temp::rf_init_subroutine = \\&main::$init_subroutine_name;}; 242# eval( q{ \$init_subroutine = \\&main::}.$init_subroutine_name);
243 # #warn "loadMacros: defining \$temp::rf_init_subroutine ",$temp::rf_init_subroutine; 243# warn "dangerousMacros: failed to compile $init_subroutine_name. $@" if $@;
244 # 244
245 # $macro_file_loaded = defined($temp::rf_init_subroutine) && defined( &{$temp::rf_init_subroutine} ); 245
246 ############################################################################### 246 ###############################################################################
247 #compile initialization subroutine. (5.6.1 version) also works with 5.6.0
248
247 no strict; 249# no strict;
248 # warn "dangerousMacros main:: contains <br>\n ".join("<br>\n ", %main::) if $debugON;
249 my $init_subroutine = eval { \&{$init_subroutine_name} }; 250 my $init_subroutine = eval { \&{$init_subroutine_name} };
250 use strict; 251# use strict;
251 my $macro_file_loaded = defined($init_subroutine); 252
252 warn "dangerousMacros: macro init $init_subroutine_name defined |$init_subroutine| |$macro_file_loaded|" if $debugON; 253 ###############################################################################
253 # macros are searched for first in the $macroDirectory of the course 254 # macros are searched for first in the $macroDirectory of the course
254 # and then in the webwork $courseScripts directory. 255 # and then in the webwork $courseScripts directory.
256
257 my $macro_file_loaded = defined($init_subroutine) && defined(&$init_subroutine);
258 warn "dangerousMacros: macro init $init_subroutine_name defined |$init_subroutine| |$macro_file_loaded|" if $debugON;
259
255 unless ($macro_file_loaded) { 260 unless ($macro_file_loaded) {
256 #print STDERR "loadMacros: loading macro file $fileName\n"; 261 #print STDERR "loadMacros: loading macro file $fileName\n";
257 if (-r "$macroDirectory$fileName") { 262 if (-r "$macroDirectory$fileName") {
258 compile_file("$macroDirectory$fileName"); 263 compile_file("$macroDirectory$fileName");
259 264
261 compile_file("$courseScriptsDirectory$fileName"); 266 compile_file("$courseScriptsDirectory$fileName");
262 } else { 267 } else {
263 die "Can't locate macro file via path: |$macroDirectory$fileName| or |$courseScriptsDirectory$fileName|"; 268 die "Can't locate macro file via path: |$macroDirectory$fileName| or |$courseScriptsDirectory$fileName|";
264 } 269 }
265 } 270 }
271 ###############################################################################
266 # Try again to define the initialization subroutine. 272 # Try again to define the initialization subroutine. (5.6.0 version)
273
267 #eval qq{ \$temp::rf_init_subroutine = \\&main::$init_subroutine_name;}; 274# eval( q{ \$init_subroutine = \\&main::}.$init_subroutine_name );
268 no strict; 275# warn "dangerousMacros: failed to compile $init_subroutine_name. $@" if $@;
276# $init_subroutine = $temp::rf_init_subroutine;
277 ###############################################################################
278 # Try again to define the initialization subroutine. (5.6.1 version) also works with 5.6.0
279
280# no strict;
269 $init_subroutine = eval { \&{'main::'.$init_subroutine_name} }; 281 $init_subroutine = eval { \&{'main::'.$init_subroutine_name} };
270 use strict; 282# use strict;
283 ###############################################################################
271 #warn "loadMacros: defining \$temp::rf_init_subroutine ",$temp::rf_init_subroutine; 284 #warn "loadMacros: defining \$temp::rf_init_subroutine ",$temp::rf_init_subroutine;
272 warn "init file defined: $macro_file_name = ", defined(&{$init_subroutine}) if $debugON; 285 $macro_file_loaded = defined($init_subroutine) && defined(&$init_subroutine);
273 286 warn "dangerousMacros: macro init $init_subroutine_name defined |$init_subroutine| |$macro_file_loaded|" if $debugON;
287
274 if ( defined($init_subroutine) && defined( &{$init_subroutine} ) ) { 288 if ( defined($init_subroutine) && defined( &{$init_subroutine} ) ) {
275 289
276 warn "dangerousMacros: initializing $macro_file_name" if $debugON; 290 warn "dangerousMacros: initializing $macro_file_name" if $debugON;
277 &$init_subroutine(); 291 &$init_subroutine();
278 } 292 }

Legend:
Removed from v.1304  
changed lines
  Added in v.1305

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9