inserting downloaded code into WebWork | topic started 2/14/2002; 11:27:43 AM last post 2/14/2002; 1:11:21 PM |
|
Michael Gage - Re: inserting downloaded code into WebWork 2/14/2002; 1:11:21 PM (reads: 1346, responses: 0) |
Hi, You've run into the security features of the PG language. Rather than to invent a new language, interpreter, etc. for writing math problems, we have instead used a powerful existing language and interpreter (perl) and cut it down so that it is not too powerful. In particular standard perl commands that directly access system calls, write to disk or interact with the outside environment in other ways, cannot be used in a standard PG problem. This prevents a problem writer editing a problem from the web from wrecking real havoc with the system, either inadvertently or on purpose. This is accomplished using the Safe.pm module supplied with perl. For example "require" cannot be used, although it is called indirectly by the "loadMacros()" command. Even print can't be used -- instead one is supposed to use the TEXT() macro, or other macros built on it. There are three places where the full power of the perl language can be used:
The first is to write a new module (a ... .pm file, such as Circle.pm)
which usually adds a new object to the list of objects available to the
PG language. In your case a "java display object". New objects are
added by writing the code in a ...pm file and then modifying the file I think that experimenting with this technique will allow you to do what you want. Once you have it working you should also think about whether it allows someone to do more than is desirable (inadvertently or not) and see if you can guard against this. The other common place to put macros that reference the disk is in the file dangerousMacros.pl which is interpreted without any of the safety checks provided by Safe.pm (hence the name of the file). This file has been used mainly to house all in one place, macros that must have access to the disk. We then try to check these macros carefully to make sure that they can't be misused. The final spot for putting macros that use the full power of perl is in PGtranslator.pm itself. This is probably not appropriate for most macros. We try to keep only really fundamental macros defined in PGtranslator.pm so that it changes relatively unfrequently. Hope this helps. -- Mike |