@@ -75,18 +75,17 @@ sub new {
7575
7676 # Holds other data, besides answers, which persists during a session and beyond.
7777 PERSISTENCE_HASH => $envir -> {PERSISTENCE_HASH } // {}, # Main data, received from DB
78- PERSISTENCE_HASH_UPDATED => {}, # Keys whose updated values should be saved by the DB
7978 answer_name_count => 0,
8079 implicit_named_answer_stack => [],
8180 implicit_answer_eval_stack => [],
8281 explicit_answer_name_evals => {},
8382 KEPT_EXTRA_ANSWERS => [],
8483 ANSWER_PREFIX => ' AnSwEr' ,
8584 ARRAY_PREFIX => ' ArRaY' ,
86- vec_num => 0, # for distinguishing matrices
85+ vec_num => 0, # for distinguishing matrices
8786 QUIZ_PREFIX => $envir -> {QUIZ_PREFIX },
8887 PG_VERSION => $ENV {PG_VERSION },
89- PG_ACTIVE => 1, # toggle to zero to stop processing
88+ PG_ACTIVE => 1, # toggle to zero to stop processing
9089 submittedAnswers => 0, # have any answers been submitted? is this the first time this session?
9190 PG_session_persistence_hash => {}, # stores data from one invoction of the session to the next.
9291 PG_original_problem_seed => 0,
@@ -477,25 +476,20 @@ sub extend_ans_group { # modifies the group type
477476 return $label ;
478477}
479478
480- sub store_persistent_data { # will store strings only (so far)
481- my ($self , $label , @values ) = @_ ;
482- if (defined ($self -> {PERSISTENCE_HASH }-> {$label })) {
483- warn " can' overwrite $label in persistent data" ;
484- } else {
485- $self -> {PERSISTENCE_HASH_UPDATED }{$label } = 1;
486- $self -> {PERSISTENCE_HASH }{$label } = join (" " , @values );
479+ # Save to or retrieve data from the persistence hash. The $label parameter is the key in the persistence hash. If the
480+ # $value parameter is not given then the value of the $label key in the hash will be returned. If the $value parameter
481+ # is given then the value of the $label key in the hash will be saved or updated. Note that if the $value parameter is
482+ # given but is undefined then the $label key will be deleted from the hash. Anything that can be JSON encoded can be
483+ # stored.
484+ sub persistent_data {
485+ my ($self , $label , $value ) = @_ ;
486+ if (@_ > 2) {
487+ if (defined $value ) {
488+ $self -> {PERSISTENCE_HASH }{$label } = $value ;
489+ } else {
490+ delete $self -> {PERSISTENCE_HASH }{$label };
491+ }
487492 }
488- $label ;
489- }
490-
491- sub update_persistent_data { # will store strings only (so far)
492- my ($self , $label , @values ) = @_ ;
493- $self -> {PERSISTENCE_HASH_UPDATED }{$label } = 1;
494- $self -> {PERSISTENCE_HASH }{$label } = join (" " , @values );
495- }
496-
497- sub get_persistent_data {
498- my ($self , $label ) = @_ ;
499493 return $self -> {PERSISTENCE_HASH }{$label };
500494}
501495
0 commit comments