# This is a simple CGI package.
 
use CGI;
 
# commandExists returns true if the URL or form include the named key
# i.e. myURL?key1=value1&key2=value2&execute=yes
execute() if CGI::commandExists( 'execute');
 
# The command key/value pairs can be retried directly. Note that all
# the keys will be upper case. Use commands() to return a copy of the
# hashmap and get() to return a more efficient pointer.
my %cmds = CGI::commands();my $who = %cmds{WHO};
my $cmds = CGI::get();my $who = %$cmds{WHO};
 
# get() can also be used to retrieve one or more named commands from
# the URL or form. There is a getWithDefault version that will return the
# default value if no such command is found.
my $who = CGI::get( 'who');# returns '' if doesn't exist
my ($who,$where) = CGI::get( 'who', 'where');
my $who = CGI::getWithDefault( 'who', 'me');
 
# A subset hash including only the commands asked for can be create...
my $subset = CGI::subset( 'who', 'me');
 
# update() will add a new command/value pair or change the value
# of an existing one. add() on the other hand will add new ones but
# leave existing ones alone. It can be used for adding defaults.
my $cmds = CGI::update( who => 'me');# add/change
my $cmds = CGI::add( who => 'you');# add but don't change
 
# Commands can be added to from a configuration file. The file contains
# lines of "key=value" or just "key" to set a blank value. It is used to load
# defaults, so if the key exists then it will not be updated from
# the configuration file. Adds ".cfg" to name file needed. More commands
# can be added from the arguments.
# Precedence is command line, configuration file, method arguments
my $cmds = CGI::addConfiguration( $file, who => 'her');
 
# Most forms and CGI parameter lines usually include an action verb.
# This method will call the correct routine based on this verb. Hence,
# "myURL?submit=Now&where=there" will call now() with the below.
# It will return the value from the call to now(), ' ' (space) if now() returns
# undefined and '' (empty) if the action verb was not found.
my $returnValue = CGI::action( 'submit', Now => \&now, 'and then' => \&then);
 
# With URL command flow it is not uncommon to have a URL control the
# flow for the next few pages. This method will look at the command "next"
# and extract the next URL to display. ` is used instead of & to separate
# parameters in next strings. `` is used to separate next groups.
# Chain commands with cmd.cgi?param=1&next=cmd2?p=2`p2=3``cmd3...
# In this example, next() will return "cmd2?p=2&p2=3&next=cmd3..."
# Returns an empty string if there are no more nexts to find.
# To use another command other than next, specify it as a parameter
my $next = CGI::next();
my $next = CGI::next( CGI::get( 'next'));
HTML::url( $next) if $next;
 
# create() will create a URL string from the program to run, and a hashmap
# of command/value pairs. Normally used to send the last not back.
HTML::url( CGI::create( 'mycmd.cgi', CGI::command(), extraOpt => 'value'));