Is there an easy way to look up which .pl file to load in order to make a certain perl utility available?
I was stiuck for a while trying to use List::Util "max", and eventually discovered it's made available by loading PGauxiliaryFunctions.pl.
Now I would like to use perl's List::Util sum and I'm tired of googling.
http://webwork.maa.org/moodle/mod/data/view.php?id=5
is probably what you are looking for. It has not been updated recently but it will find most subroutines available in the PG safe compartment.
Importing a new CPAN module into the PG safe compartment is a bigger deal and takes more work. It has to be listed in the appropriate list in defaults.config. (You'll see where the the CPAN modules are loaded). I think you found the local version of "max" not the one from List::Utils
I don't think there is a "sum" subroutine but it is pretty easy to implement yourself. You can place new subroutines in a macro file such as mymacros.pl
and place this in myCourse/templates/macros and reference it from the .pg
files that you write.
Hope this helps.
Mike
Perl 5.20.2 has it, the command
In defaults.conf, do you mean section starting here?
use List::Util "sum"loads a working "sum" command.
In defaults.conf, do you mean section starting here?
${pg}{modules} = [
[qw(HTML::Parser)],
[qw(HTML::Entities)],
[qw(DynaLoader)],
I added a line "[qw(List::Util::sum)]", also tried "[qw(List::Util]", but neither worked. Would it be necessary to call "sum" using a namespace prefix of some kind?
Now that you mention it, I see that PGauxiliaryFunctions.pl does just reimplement some utilities from List::Util. In these (and my) case that's easy to do, but I'd rather learn how to avoid reinventing the wheel.
Thanks for that link, just what I was looking for. I had stumbled across it before but couldn't locate it when I needed it.
A good example of a handy perl function I wouldn't want to reimplement myself from scratch is Data::Dumper. I'd love to get that working.
[ qw(List::Util) ],
Should do it. You'll need to restart.
However I would advise against doing it, particularly for something simple like
sum or max.
The .pg and macros problems are run inside a Safe.pm compartment to keep code in one the problems from inadvertently (or maliciously) doing something like erasing the hard drive. Basically all functions that print or have access to the hard drive are passed through PG functions that limit their abilities (and could limit them more if we find an exploit). So far there have been, as far as we know, no security breaches through WeBWorK. Probably mostly because people aren't trying very hard, but we want to protect things as much as we can.
Think whether you really need Data::Dumper inside the Safe compartment that renders the .pg problem. Often there is another way.
Data::Dumper is available outside in the webwork2 directory that handles that LMS portion of WeBWorK but that portion doesn't use lots of evals to evaluate outside code.
-- Mike
You mean restart the http server? I did that. Also tried making Data::Dumper available in the same way, that also failed.
Are sum and max really potentially unsafe? More so than the thousand other functions that are included in the safe compartment?
Moreover, I would only be running Dumper on my office computer for the purpose of writing problems, it would not be on the actual server.
The following statement is cryptic to me.
"Data::Dumper is available outside in the webwork2 directory that handles that LMS portion of WeBWorK but that portion doesn't use lots of evals to evaluate outside code."
Could you expand? Is there an easy way to make Dumper available?
Are sum and max really potentially unsafe? More so than the thousand other functions that are included in the safe compartment?
Moreover, I would only be running Dumper on my office computer for the purpose of writing problems, it would not be on the actual server.
The following statement is cryptic to me.
"Data::Dumper is available outside in the webwork2 directory that handles that LMS portion of WeBWorK but that portion doesn't use lots of evals to evaluate outside code."
Could you expand? Is there an easy way to make Dumper available?
All of the code in the webwork2 directory runs outside the Safe compartment (as opposed to code in the pg directory much of which is inside Safe). That means you can add CPAN modules easily to webwork2 code.
Importing CPAN modules into the Safe compartment is always tricky. I'm surprised that you aren't able to add Data::Dumper by adding it to the module list -- but I don't know exactly why it didn't work. This is getting a bit specialized so you might want to ask about this on the webwork-devel mailing list to see if there is some developer who has gotten Data::Dumper to work inside Safe.
You can join at http://webwork.maa.org/wiki/Mailing_Lists .
Sorry, I'm still not grokking. How is it exactly that one goes about easily adding modules to webwork2 code? What file do I edit?
Thanks for the link, I'll check that out.
Thanks for the link, I'll check that out.