Parent Directory
|
Revision Log
regularizing calls to no_null -- something puzzling is going on here since it appears to work on some systems but not others.
1 ################################################################################ 2 # WeBWorK Online Homework Delivery System 3 # Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ 4 # $CVSHeader: pg/lib/PGanswergroup.pm,v 1.1 2010/05/14 11:39:02 gage Exp $ 5 # 6 # This program is free software; you can redistribute it and/or modify it under 7 # the terms of either: (a) the GNU General Public License as published by the 8 # Free Software Foundation; either version 2, or (at your option) any later 9 # version, or (b) the "Artistic License" which comes with this package. 10 # 11 # This program is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the 14 # Artistic License for more details. 15 ################################################################################ 16 package PGanswergroup; 17 use Exporter; 18 use PGcore qw(not_null); 19 use PGresponsegroup; 20 21 our @ISA=qw(PGcore); 22 23 ############################################# 24 # An object which contains an answer label and 25 # an answer evaluator 26 # and the links to and contents of all associated answer blanks 27 # (i.e the student responses) 28 ############################################# 29 # Notes 30 # Answergroup -- input to a single answerEvaluator, may have several answer blanks 31 # for example an array or a radio button group or several checkboxes 32 # 1. create a answerEvaluator label name 33 # 2. provide space for an answerEvaluator 34 # 3. indicate that an answer blank or blanks has been published to receive the responses 35 # for example store the number of response strings associated with this answerEvaluator label name 36 # 4. space for the contents of the responses is provided in the PGresponse group 37 # 5. provide a method for applying the evaluator to the responses 38 # 39 # use Tie: IxHash??? to create ordered hash? (see Perl Cookbook) 40 41 sub new { 42 my $class = shift; 43 my $label = shift; 44 my $self = { 45 ans_label => $label, 46 ans_eval => undef, # usually an AnswerEvaluator, sometimes a CODE 47 response => new PGresponsegroup($label), # A PGresponse object which holds the responses 48 # which make up the answer 49 active => 1, # whether this answer group is currently active (for multistate problems) 50 51 @_, 52 }; 53 bless $self, $class; 54 return $self; 55 56 } 57 58 sub evaluate { # applies the answer evaluator to the student response and returns an answer hash 59 60 61 62 } 63 64 sub complete { # test to see if answer evaluator and appropriate response blanks are all present 65 66 67 68 } 69 sub ans_eval { 70 my $self = shift; 71 my $ans_eval = shift; 72 $self->{ans_eval}= $ans_eval if ref($ans_eval); 73 $self->{ans_eval}; 74 } 75 sub append_responses { #add or modify a response to the PGresponsegroup object 76 my $self = shift; 77 my @response_list = @_; # ordered list of label/ value pairs 78 $self->{response}->append_responses(@response_list); 79 } 80 81 sub insert_responses { # add a group of responses ( label/value pairs) 82 my $self = shift; 83 my @response_list = @_; 84 $self->{response}->clear(); 85 $self->{response}->append_responses(@response_list); 86 } 87 88 sub insert_response_value { # add a response value(with label defined by answer group label) 89 my $self = shift; 90 my $value = shift; 91 $self->{response}->append_reponse($self->{ans_label}, $value); 92 } 93 sub replace_response { # add a response value(with label defined by answer group label) 94 my $self = shift; 95 my $response_label = shift; 96 my $value = shift; 97 $self->{response}->replace_response($response_label, $value); 98 } 99 sub insert { # add new values to PGanswergroup keys preserve existing values 100 my $self = shift; 101 my @in = @_; 102 my %hash = (); 103 if ( ref($in[0]=~/HASH/) ) { 104 %hash = %{$in[0]}; 105 } else { 106 %hash = @in; 107 } 108 foreach my $key (keys %hash) { 109 next if not_null( $self->{$key} ); 110 $self->{$key} = $hash{$key}; 111 } 112 $self; 113 } 114 115 116 sub replace { # add new values ot PGanswergroup, overwriting existing values when duplicated 117 my $self = shift; 118 my @in = @_; 119 my %hash = (); 120 if ( ref($in[0]=~/HASH/) ) { 121 %hash = %{$in[0]}; 122 } else { 123 %hash = @in; 124 } 125 foreach my $key (keys %hash) { 126 $self->{$key} = $hash{$key}; 127 } 128 $self; 129 } 130 131 132 133 134 sub delete_from_hash { # don't want to redefine delete 135 my $self = shift; 136 my @in = @_; 137 my %hash = (); 138 if ( ref($in[0]=~/HASH/) ) { 139 %hash = %{$in[0]}; 140 } else { 141 %hash = @in; 142 } 143 foreach my $key (keys %hash) { 144 $self->{$key} = undef; 145 } 146 $self; 147 } 148 149 150 1;
aubreyja at gmail dot com | ViewVC Help |
Powered by ViewVC 1.0.9 |