IMPORTING CGI METHOD CALLS INTO YOUR NAME SPACE

As a convenience, you can import most of the CGI method calls directly into your name space. The syntax for doing this is:

	use CGI <list of methods>;

The listed methods will be imported into the current package; you can call them directly without creating a CGI object first. This example shows how to import the param() and header() methods, and then use them directly:

	use CGI param,header;
	print header('text/plain');
	$zipcode = param('zipcode');

You can import groups of methods by referring to a number of special names:

cgi
Import all CGI-handling methods, such as param(), path_info() and the like.

form
Import all fill-out form generating methods, such as textfield().

html2
Import all methods that generate HTML 2.0 standard elements.

html3
Import all methods that generate HTML 3.0 proposed elements (such as <table>, <super> and <sub>).

netscape
Import all methods that generate Netscape-specific HTML extensions.

shortcuts
Import all HTML-generating shortcuts (i.e. 'html2' + 'html3' + 'netscape')...

standard
Import ``standard'' features, 'html2', 'form' and 'cgi'.

all
Import all the available methods. For the full list, see the CGI.pm code, where the variable %TAGS is defined.

Note that in the interests of execution speed CGI.pm does not use the standard Exporter syntax for specifying load symbols. This may change in the future.

If you import any of the state-maintaining CGI or form-generating methods, a default CGI object will be created and initialized automatically the first time you use any of the methods that require one to be present. This includes param(), textfield(), submit() and the like. (If you need direct access to the CGI object, you can find it in the global variable $CGI::Q). By importing CGI.pm methods, you can create visually elegant scripts:

   use CGI standard,html2;
   print 
       header,
       start_html('Simple Script'),
       h1('Simple Script'),
       start_form,
       "What's your name? ",textfield('name'),p,
       "What's the combination?",
       checkbox_group(-name=>'words',
		      -values=>['eenie','meenie','minie','moe'],
		      -defaults=>['eenie','moe']),p,
       "What's your favorite color?",
       popup_menu(-name=>'color',
		  -values=>['red','green','blue','chartreuse']),p,
       submit,
       end_form,
       hr,"\n";

    if (param) {
       print 
	   "Your name is ",em(param('name')),p,
	   "The keywords are: ",em(join(", ",param('words'))),p,
	   "Your favorite color is ",em(param('color')),".\n";
    }
    print end_html;