Chapter 11
The next call, to start_mode(), sets list as the default run mode. When the
CGI is called without an rm parameter set, the run mode will be list. This is gen
erally what happens when the user first hits the application which is why it's
called start_mode() and not default_mode().
Finally, run_modes() sets up the run mode table. The keys are names of run
modes and the values are method names. Notice that the application defines a run
mode named new but uses the method name new_message(). Using new() would
have caused problems since CGI::Application defines a new() method already and
the BBS class is derived from CGI::Application.
After that, the class implements each of its run modes as a separate method.
For example, the list() method looks like this:
# show list of messages
sub list {
my $self = shift;
my $query = $self >query;
my $output;
# ...
return $output;
}
Since run modes are methods, they receive their object as the first parameter
($self). The inherited query() method is used to create and return a CGI.pm
object. As a result, the internals of the function may be very similar to the pure
CGI.pm implementation shown earlier. However, there is one major difference
CGI::Application run mode methods must never print directly to STDOUT. Instead,
they return their output.
CAUTION Never print to STDOUT from a CGI::Application run mode. All
output must be returned as a string.
Since all run modes are methods, transferring control from one to another is
easy. For example, the save() method is intended to show the list of messages
when it finishes saving the message. To do this it just calls list() at the end of the
method and returns the result:
262
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved