Input Type Programming for Mallard


What methods must my input type module contain? What do they DO?

What about methods inherited from the parent InputType.pm?

All of your new input types should inherit the InputType.pm basic type. You may do this by simply typing

@ISA = qw(Types::InputType);
after the package statement.

Your type will then inherit the following methods from InputType.pm. Note that you can call these methods as $self->method().

Just what kind of interface are my input type methods dealing with?

Questions are asked by the ask() method and graded by the grade() method in the Mallard Question module. These Question methods call your corresponding input module methods.

The Question module takes care of both parsing the text file containing the actual quiz questions (written by course developers), and reading the CGI form variables containing the student's submitted answer. It then prepares from these sources the variables that are sent to the methods in the input type modules you will write. The interfaces for each of the basic methods are given below.

What is the interface for ask()?

What is the interface for grade()?

What is the interface for cheat()?

What is the interface for display()?

How is the question file parsed to get the variables mentioned above?

Below is a generic example of a question file. The line numbers are for illustrative purposes only, they will be used in the following discussion.

1   <question>
2   Text of the question.
3   <input type=my_type param1=value1>
4   <param param2=value2>
5   data1
6   data2
7   data3
8   </input>
9   <answer>
10   data1
11   data2
12   data3
13   </answer>
14   </question>

Can I send variables I generate in ask() into grade()?

Sometimes you will generate variables in ask() that you might like to reuse during grade(). For example, you might use a function of the data contained in @$question_data to select a gif file to display, and not wish to redo the computation again in the grade() method. Or you might generate a random number in ask() that must be sent to grade() to be used there, as it cannot be regenerated.

Although the ask() and grade() methods are sent much of the same data (@$question_data and @$answer_data for instance) you cannot store your newly generated variables in those arrays.

Why not? Because the display of a quiz in "asking" mode and the display of the same quiz in "grading" mode when the student submits it are two separate CGI processes. The question file is parsed anew in each process, and the various arrays are created anew from data in that question file as described above.

The one way to pass variables from ask() to grade() is to put those variables into the %$answers hash. To do this, simply create an HTML input element of type hidden which contains the variable, as follows:

	<INPUT TYPE=HIDDEN NAME={$prefix}myvar VALUE=$myvar>
	
You may then retrieve these variables in the grade() method via the %$answers hash, in the same way that you retrieve student answers. Note that you must use the $prefix in these hidden element names exactly as you use $prefix when generating the input elements that will contain the student responses.

WARNING!!! Don't forget that the students will see the value of these hidden elements if they do a view source on the quiz page, because they are generated and written to the quiz page source during parsing. Therefore you must not send any secret data (such as, say, the answer to the question!) from ask() to grade() in this manner.

Any suggestions for making my types fit with the overall look of Mallard?

Making your new type have a similar visual "look" as the types that come packaged with a basic Mallard installation is largely a matter of adhering to the following guidelines when coding your grade() method.

How is a display type reference in material parsed to get the variables mentioned above?

Display types may be used to display data in any place where regular HTML text may be used. This may be in the leading text of a quiz, inside generic course material files, or inside the text of a question. They will be displayed by the text display method in either the Question or Document module, depending on where they are used. This text display method will then instantiate a display item of your type and call its display() method, passing in the variables explained above.

Below is a generic example of a display type used in course material. The line numbers are for illustrative purposes only, they will be used in the following discussion.

1   Text appearing before the display item in the material.
2   <display type=my_type param1=value1>
3   <param param2=value2>
4   data1
5   data2
6   data3
7   </display>
8   Text follwing the display item

How can I test new input types I develop?


Questions? Comments? General harrassment? Mail it to maiko@wocket.csl.uiuc.edu.