Forum archive 2000-2006

David Baur - use XML::Parser in a pg/lib/ .pm file

David Baur - use XML::Parser in a pg/lib/ .pm file

by Arnold Pizer -
Number of replies: 0
inactiveTopicuse XML::Parser in a pg/lib/ .pm file topic started 7/10/2006; 6:11:16 PM
last post 7/10/2006; 7:13:25 PM
userDavid Baur - use XML::Parser in a pg/lib/ .pm file  blueArrow
7/10/2006; 6:11:16 PM (reads: 253, responses: 1)
Hello again. I'm still working on that Java evaluator that I mentioned earlier, and I've run into a bit of trouble. To better explain my problem I feel I should first explain my approach. Right now the project consists primarily of 3 files :

1)

pg/lib/Java.pm, which houses the bulk of my code and handles copying, compiling, and grading of a student's java code and returns the results (score, message, etc) in the form of a hash similar to an answerhash.

2)

pg/macros/javaAnswerEvaluators.pl, which introduces a java_cmp evaluator which is essentially a wrapper for Java.pm based off of the evaluators in extraAnswerEvaluators.pl

3)

customfolder/WWTestRunner.java, which runs a JUnit test on a student's java code and gives customized output in a proprietary format for parsing by Java.pm

As it is right now, all of this works fine. For the sake of friendliness and expandability, however, I am trying to turn WWTestRunner's output into proper XML. I have modified WWTestRunner to output XML, but I am having trouble setting up Java.pm to parse it. The code to set up a parser in Java.pm looks something like:

use XML::Parser;

my $XMLparser = new XML::Parser( Style => 'Debug' );

my $XMLobj = $XMLparser->parsefile($fileName);

and webwork says:

Can't locate object method "new" via package "XML::Parser" (perhaps you forgot to load "XML::Parser"?) at /opt/pg/lib/Java.pm line 103, chunk 1.

So from what I've gathered, it looks like "use" doesn't work because of the way the modules are loaded. Is this correct? If so, I was wondering if there was another way to load XML::Parser or a better way to structure this process to get around it.

Thanks

-David

EDIT: I apologize for any formatting issues, and swear to never compose a post in notepad ever again.

<| Post or View Comments |>


userMichael Gage - Re: use XML::Parser in a pg/lib/ .pm file  blueArrow
7/10/2006; 7:13:25 PM (reads: 314, responses: 0)
So from what I've gathered, it looks like "use" doesn't work because of the way the modules are loaded. Is this correct? If so, I was wondering if there was another way to load XML::Parser or a better way to structure this process to get around it.

I believe you have the correct diagnosis of the problem. A similar thing takes place with Matrix.pm and RealMatrix1.pm;

Try adding [qw(XML::Parser)] to the pg modules to load in global.conf. (Don't forget to restart the server.)

This is likely to solve your original problem. It also makes the subroutines in XML::Parser generally available. Conceivably this might become security concern, but I haven't thought closely about this. I would worry about this later.

If so there are security risks some modules such as Safe::Hole and Safe::World which might be of help (they are on CPAN, but I haven't worked with them.)

Hope this helps.

-- Mike Gage

<| Post or View Comments |>