[system] / trunk / pg / macros / parserPopUp.pl Repository:
ViewVC logotype

View of /trunk/pg/macros/parserPopUp.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5392 - (download) (as text) (annotate)
Sun Aug 19 21:50:23 2007 UTC (12 years, 6 months ago) by dpvc
File size: 1969 byte(s)
Move the context creation to the _init routine so that modifications
to main:: occur at initialization time, not when the file is loaded.

    1 loadMacros('MathObjects.pl','contextString.pl');
    2 
    3 sub _parserPopUp_init {parserPopUp::Init()}; # don't reload this file
    4 
    5 =head1 DESCRIPTION
    6 
    7  ####################################################################
    8  #
    9  #  This file implements a pop-up menu object that is compatible
   10  #  with Value objects, and in particular, with the MultiPart object.
   11  #
   12  #  To create a PopUp object, use
   13  #
   14  #    $popup = PopUp([choices,...],correct);
   15  #
   16  #  where "choices" are the strings for the items in the popup menu,
   17  #  and "correct" is the choice that is the correct answer for the
   18  #  popup.
   19  #
   20  #  To insert the popup menu into the problem text, use
   21  #
   22  #    BEGIN_TEXT
   23  #      \{$popup->menu\}
   24  #    END_TEXT
   25  #
   26  #  and then
   27  #
   28  #    ANS($popup->cmp);
   29  #
   30  #  to get the answer checker for the popup.
   31  #
   32  #  You can use the PopUp menu object in MultiPart objects.  This is
   33  #  the reason for the pop-up menu's ans_rule method (since that is what
   34  #  MultiPart calls to get answer rules).
   35  #
   36 
   37 =cut
   38 
   39 #
   40 #  The package that implements pop-up menus
   41 #
   42 package parserPopUp;
   43 our @ISA = qw(Value::String);
   44 
   45 #
   46 #  Setup the main:: namespace
   47 #
   48 sub Init {main::PG_restricted_eval('sub PopUp {parserPopUp->new(@_)}')}
   49 
   50 #
   51 #  Create a new PopUp object
   52 #
   53 sub new {
   54   my $self = shift; my $class = ref($self) || $self;
   55   my $choices = shift; my $value = shift;
   56   Value::Error("A PopUp's first argument should be a list of menu items")
   57     unless ref($choices) eq 'ARRAY';
   58   Value::Error("A PopUp's second argument should be the correct menu choice")
   59     unless defined($value) && $value ne "";
   60   my $context = Parser::Context->getCopy("String");
   61   $context->strings->add(map {$_=>{}} @{$choices});
   62   my $self = bless $context->Package("String")->new($context,$value)->with(choices => $choices), $class;
   63   return $self;
   64 }
   65 
   66 #
   67 #  Create the menu list
   68 #
   69 sub menu {
   70   my $self = shift;
   71   main::pop_up_list($self->{choices});
   72 }
   73 
   74 #
   75 #  Answer rule is the menu list
   76 #
   77 sub ans_rule {shift->menu(@_)}
   78 
   79 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9