1CGI::Simple(3)        User Contributed Perl Documentation       CGI::Simple(3)
2
3
4

NAME

6       CGI::Simple - A Simple totally OO CGI interface that is CGI.pm
7       compliant
8

VERSION

10       This document describes CGI::Simple version 1.113.
11

SYNOPSIS

13           use CGI::Simple;
14           $CGI::Simple::POST_MAX = 1024;       # max upload via post default 100kB
15           $CGI::Simple::DISABLE_UPLOADS = 0;   # enable uploads
16
17           $q = new CGI::Simple;
18           $q = new CGI::Simple( { 'foo'=>'1', 'bar'=>[2,3,4] } );
19           $q = new CGI::Simple( 'foo=1&bar=2&bar=3&bar=4' );
20           $q = new CGI::Simple( \*FILEHANDLE );
21
22           $q->save( \*FILEHANDLE );   # save current object to a file as used by new
23
24           @params = $q->param;        # return all param names as a list
25           $value = $q->param('foo');  # return the first value supplied for 'foo'
26           @values = $q->param('foo'); # return all values supplied for foo
27
28           %fields   = $q->Vars;      # returns untied key value pair hash
29           $hash_ref = $q->Vars;      # or as a hash ref
30           %fields   = $q->Vars("|"); # packs multiple values with "|" rather than "\0";
31
32           @keywords = $q->keywords;  # return all keywords as a list
33
34           $q->param( 'foo', 'some', 'new', 'values' );      # set new 'foo' values
35           $q->param( -name=>'foo', -value=>'bar' );
36           $q->param( -name=>'foo', -value=>['bar','baz'] );
37
38           $q->param( 'foo', 'some', 'new', 'values' );      # append values to 'foo'
39           $q->append( -name=>'foo', -value=>'bar' );
40           $q->append( -name=>'foo', -value=>['some', 'new', 'values'] );
41
42           $q->delete('foo'); # delete param 'foo' and all its values
43           $q->delete_all;    # delete everything
44
45           <INPUT TYPE="file" NAME="upload_file" SIZE="42">
46
47           $files    = $q->upload()                # number of files uploaded
48           @files    = $q->upload();               # names of all uploaded files
49           $filename = $q->param('upload_file')    # filename of uploaded file
50           $mime     = $q->upload_info($filename,'mime'); # MIME type of uploaded file
51           $size     = $q->upload_info($filename,'size'); # size of uploaded file
52
53           my $fh = $q->upload($filename);         # get filehandle to read from
54           while ( read( $fh, $buffer, 1024 ) ) { ... }
55
56           # short and sweet upload
57           $ok = $q->upload( $q->param('upload_file'), '/path/to/write/file.name' );
58           print "Uploaded ".$q->param('upload_file')." and wrote it OK!" if $ok;
59
60           $decoded    = $q->url_decode($encoded);
61           $encoded    = $q->url_encode($unencoded);
62           $escaped    = $q->escapeHTML('<>"&');
63           $unescaped  = $q->unescapeHTML('&lt;&gt;&quot;&amp;');
64
65           $qs = $q->query_string; # get all data in $q as a query string OK for GET
66
67           $q->no_cache(1);        # set Pragma: no-cache + expires
68           print $q->header();     # print a simple header
69           # get a complex header
70           $header = $q->header(   -type       => 'image/gif'
71                                   -nph        => 1,
72                                   -status     => '402 Payment required',
73                                   -expires    =>'+24h',
74                                   -cookie     => $cookie,
75                                   -charset    => 'utf-7',
76                                   -attachment => 'foo.gif',
77                                   -Cost       => '$2.00'
78                               );
79           # a p3p header (OK for redirect use as well)
80           $header = $q->header( -p3p => 'policyref="http://somesite.com/P3P/PolicyReferences.xml' );
81
82           @cookies = $q->cookie();        # get names of all available cookies
83           $value   = $q->cookie('foo')    # get first value of cookie 'foo'
84           @value   = $q->cookie('foo')    # get all values of cookie 'foo'
85           # get a cookie formatted for header() method
86           $cookie  = $q->cookie(  -name    => 'Password',
87                                   -values  => ['superuser','god','my dog woofie'],
88                                   -expires => '+3d',
89                                   -domain  => '.nowhere.com',
90                                   -path    => '/cgi-bin/database',
91                                   -secure  => 1
92                                );
93           print $q->header( -cookie=>$cookie );       # set cookie
94
95           print $q->redirect('http://go.away.now');   # print a redirect header
96
97           dienice( $q->cgi_error ) if $q->cgi_error;
98

DESCRIPTION

100       CGI::Simple provides a relatively lightweight drop in replacement for
101       CGI.pm.  It shares an identical OO interface to CGI.pm for parameter
102       parsing, file upload, cookie handling and header generation. This
103       module is entirely object oriented, however a complete functional
104       interface is available by using the CGI::Simple::Standard module.
105
106       Essentially everything in CGI.pm that relates to the CGI (not HTML)
107       side of things is available. There are even a few new methods and
108       additions to old ones! If you are interested in what has gone on under
109       the hood see the Compatibility with CGI.pm section at the end.
110
111       In practical testing this module loads and runs about twice as fast as
112       CGI.pm depending on the precise task.
113

CALLING CGI::Simple ROUTINES USING THE OBJECT INTERFACE

115       Here is a very brief rundown on how you use the interface. Full details
116       follow.
117
118   First you need to initialize an object
119       Before you can call a CGI::Simple method you must create a CGI::Simple
120       object.  You do that by using the module and then calling the new()
121       constructor:
122
123           use CGI::Simple;
124           my $q = new CGI::Simple;
125
126       It is traditional to call your object $q for query or perhaps $cgi.
127
128   Next you call methods on that object
129       Once you have your object you can call methods on it using the -> arrow
130       syntax For example to get the names of all the parameters passed to
131       your script you would just write:
132
133           @names = $q->param();
134
135       Many methods are sensitive to the context in which you call them. In
136       the example above the param() method returns a list of all the
137       parameter names when called without any arguments.
138
139       When you call param('arg') with a single argument it assumes you want
140       to get the value(s) associated with that argument (parameter). If you
141       ask for an array it gives you an array of all the values associated
142       with it's argument:
143
144           @values = $q->param('foo');  # get all the values for 'foo'
145
146       whereas if you ask for a scalar like this:
147
148           $value = $q->param('foo');   # get only the first value for 'foo'
149
150       then it returns only the first value (if more than one value for 'foo'
151       exists).
152
153       Most CGI::Simple routines accept several arguments, sometimes as many
154       as 10 optional ones!  To simplify this interface, all routines use a
155       named argument calling style that looks like this:
156
157           print $q->header( -type=>'image/gif', -expires=>'+3d' );
158
159       Each argument name is preceded by a dash.  Neither case nor order
160       matters in the argument list.  -type, -Type, and -TYPE are all
161       acceptable.
162
163       Several routines are commonly called with just one argument.  In the
164       case of these routines you can provide the single argument without an
165       argument name.  header() happens to be one of these routines.  In this
166       case, the single argument is the document type.
167
168          print $q->header('text/html');
169
170       Sometimes methods expect a scalar, sometimes a reference to an array,
171       and sometimes a reference to a hash.  Often, you can pass any type of
172       argument and the routine will do whatever is most appropriate.  For
173       example, the param() method can be used to set a CGI parameter to a
174       single or a multi-valued value.  The two cases are shown below:
175
176          $q->param(-name=>'veggie',-value=>'tomato');
177          $q->param(-name=>'veggie',-value=>['tomato','tomahto','potato','potahto']);
178

CALLING CGI::Simple ROUTINES USING THE FUNCTION INTERFACE

180       For convenience a functional interface is provided by the
181       CGI::Simple::Standard module. This hides the OO details from you and
182       allows you to simply call methods. You may either use AUTOLOADING of
183       methods or import specific method sets into you namespace. Here are the
184       first few examples again using the function interface.
185
186           use CGI::Simple::Standard qw(-autoload);
187           @names  = param();
188           @values = param('foo');
189           $value  = param('foo');
190           print header(-type=>'image/gif',-expires=>'+3d');
191           print header('text/html');
192
193       Yes that's it. Not a $q-> in sight. You just use the module and select
194       how/which methods to load. You then just call the methods you want
195       exactly as before but without the $q-> notation.
196
197       When (if) you read the following docs and are using the functional
198       interface just pretend the $q-> is not there.
199
200   Selecting which methods to load
201       When you use the functional interface Perl needs to be able to find the
202       functions you call. The simplest way of doing this is to use
203       autoloading as shown above. When you use CGI::Simple::Standard with the
204       '-autoload' pragma it exports a single AUTOLOAD sub into you namespace.
205       Every time you call a non existent function AUTOLOAD is called and will
206       load the required function and install it in your namespace. Thus only
207       the AUTOLOAD sub and those functions you specifically call will be
208       imported.
209
210       Alternatively CGI::Simple::Standard provides a range of function sets
211       you can import or you can just select exactly what you want. You do
212       this using the familiar
213
214           use CGI::Simple::Standard qw( :func_set  some_func);
215
216       notation. This will import the ':func_set' function set and the
217       specific function 'some_func'.
218
219   To Autoload or not to Autoload, that is the question.
220       If you do not have a AUTOLOAD sub in you script it is generally best to
221       use the '-autoload' option. Under autoload you can use any method you
222       want but only import and compile those functions you actually use.
223
224       If you do not use autoload you must specify what functions to import.
225       You can only use functions that you have imported. For comvenience
226       functions are grouped into related sets. If you choose to import one or
227       more ':func_set' you may have potential namespace collisions so check
228       out the docs to see what gets imported. Using the ':all' tag is pretty
229       slack but it is there if you want. Full details of the function sets
230       are provided in the CGI::Simple::Standard docs
231
232       If you just want say the param and header methods just load these two.
233
234           use CGI::Simple::Standard qw(param header);
235
236   Setting globals using the functional interface
237       Where you see global variables being set using the syntax:
238
239           $CGI::Simple::DEBUG = 1;
240
241       You use exactly the same syntax when using CGI::Simple::Standard.
242

THE CORE METHODS

244   new() Creating a new query object
245       The first step in using CGI::Simple is to create a new query object
246       using the new() constructor:
247
248            $q = new CGI::Simple;
249
250       This will parse the input (from both POST and GET methods) and store it
251       into an object called $q.
252
253       If you provide a file handle to the new() method, it will read
254       parameters from the file (or STDIN, or whatever).
255
256            open FH, "test.in" or die $!;
257            $q = new CGI::Simple(\*FH);
258
259            open $fh, "test.in" or die $!;
260            $q = new CGI::Simple($fh);
261
262       The file should be a series of newline delimited TAG=VALUE pairs.
263       Conveniently, this type of file is created by the save() method (see
264       below). Multiple records can be saved and restored.  IO::File objects
265       work fine.
266
267       If you are using the function-oriented interface provided by
268       CGI::Simple::Standard and want to initialize from a file handle, the
269       way to do this is with restore_parameters().  This will (re)initialize
270       the default CGI::Simple object from the indicated file handle.
271
272           restore_parameters(\*FH);
273
274       In fact for all intents and purposes restore_parameters() is identical
275       to new() Note that restore_parameters() does not exist in CGI::Simple
276       itself so you can't use it.
277
278       You can also initialize the query object from an associative array
279       reference:
280
281           $q = new CGI::Simple( { 'dinosaur' => 'barney',
282                                   'song'     => 'I love you',
283                                   'friends'  => [qw/Jessica George Nancy/] }
284                               );
285
286       or from a properly formatted, URL-escaped query string:
287
288           $q = new CGI::Simple( 'dinosaur=barney&color=purple' );
289
290       or from a previously existing CGI::Simple object (this generates an
291       identical clone including all global variable settings, etc that are
292       stored in the object):
293
294           $old_query = new CGI::Simple;
295           $new_query = new CGI::Simple($old_query);
296
297       To create an empty query, initialize it from an empty string or hash:
298
299           $empty_query = new CGI::Simple("");
300
301              -or-
302
303           $empty_query = new CGI::Simple({});
304
305   keywords() Fetching a list of keywords from a query
306           @keywords = $q->keywords;
307
308       If the script was invoked as the result of an <ISINDEX> search, the
309       parsed keywords can be obtained as an array using the keywords()
310       method.
311
312   param() Fetching the names of all parameters passed to your script
313           @names = $q->param;
314
315       If the script was invoked with a parameter list (e.g.
316       "name1=value1&name2=value2&name3=value3"), the param() method will
317       return the parameter names as a list.  If the script was invoked as an
318       <ISINDEX> script and contains a string without ampersands (e.g.
319       "value1+value2+value3") , there will be a single parameter named
320       "keywords" containing the "+"-delimited keywords.
321
322       NOTE: The array of parameter names returned will be in the same order
323       as they were submitted by the browser.  Usually this order is the same
324       as the order in which the parameters are defined in the form (however,
325       this isn't part of the spec, and so isn't guaranteed).
326
327   param() Fetching the value or values of a simple named parameter
328           @values = $q->param('foo');
329
330                 -or-
331
332           $value = $q->param('foo');
333
334       Pass the param() method a single argument to fetch the value of the
335       named parameter. If the parameter is multi-valued (e.g. from multiple
336       selections in a scrolling list), you can ask to receive an array.
337       Otherwise the method will return a single value.
338
339       If a value is not given in the query string, as in the queries
340       "name1=&name2=" or "name1&name2", it will be returned by default as an
341       empty string. If you set the global variable:
342
343           $CGI::Simple::NO_UNDEF_PARAMS = 1;
344
345       Then value-less parameters will be ignored, and will not exist in the
346       query object. If you try to access them via param you will get an undef
347       return value.
348
349   param() Setting the values of a named parameter
350           $q->param('foo','an','array','of','values');
351
352       This sets the value for the named parameter 'foo' to an array of
353       values.  This is one way to change the value of a field.
354
355       param() also recognizes a named parameter style of calling described in
356       more detail later:
357
358           $q->param(-name=>'foo',-values=>['an','array','of','values']);
359
360                         -or-
361
362           $q->param(-name=>'foo',-value=>'the value');
363
364   param() Retrieving non-application/x-www-form-urlencoded data
365       If POSTed or PUTed data is not of type
366       application/x-www-form-urlencoded or multipart/form-data, then the data
367       will not be processed, but instead be returned as-is in a parameter
368       named POSTDATA or PUTDATA.  To retrieve it, use code like this:
369
370           my $data = $q->param( 'POSTDATA' );
371
372                         -or-
373
374           my $data = $q->param( 'PUTDATA' );
375
376       (If you don't know what the preceding means, don't worry about it.  It
377       only affects people trying to use CGI::Simple for REST webservices)
378
379   add_param() Setting the values of a named parameter
380       You nay also use the new method add_param to add parameters. This is an
381       alias to the _add_param() internal method that actually does all the
382       work.  You can call it like this:
383
384           $q->add_param('foo', 'new');
385           $q->add_param('foo', [1,2,3,4,5]);
386           $q->add_param( 'foo', 'bar', 'overwrite' );
387
388       The first argument is the parameter, the second the value or an array
389       ref of values and the optional third argument sets overwrite mode. If
390       the third argument is absent of false the values will be appended. If
391       true the values will overwrite any existing ones
392
393   append() Appending values to a named parameter
394          $q->append(-name=>'foo',-values=>['yet','more','values']);
395
396       This adds a value or list of values to the named parameter.  The values
397       are appended to the end of the parameter if it already exists.
398       Otherwise the parameter is created.  Note that this method only
399       recognizes the named argument calling syntax.
400
401   import_names() Importing all parameters into a namespace.
402       This method was silly, non OO and has been deleted. You can get all the
403       params as a hash using Vars or via all the other accessors.
404
405   delete() Deleting a parameter completely
406           $q->delete('foo');
407
408       This completely clears a parameter. If you are using the function call
409       interface, use Delete() instead to avoid conflicts with Perl's built-in
410       delete operator.
411
412       If you are using the function call interface, use Delete() instead to
413       avoid conflicts with Perl's built-in delete operator.
414
415   delete_all() Deleting all parameters
416           $q->delete_all();
417
418       This clears the CGI::Simple object completely. For CGI.pm compatibility
419       Delete_all() is provided however there is no reason to use this in the
420       function call interface other than symmetry.
421
422       For CGI.pm compatibility Delete_all() is provided as an alias for
423       delete_all however there is no reason to use this, even in the function
424       call interface.
425
426   param_fetch() Direct access to the parameter list
427       This method is provided for CGI.pm compatibility only. It returns an
428       array ref to the values associated with a named param. It is
429       deprecated.
430
431   Vars() Fetching the entire parameter list as a hash
432           $params = $q->Vars;  # as a tied hash ref
433           print $params->{'address'};
434           @foo = split "\0", $params->{'foo'};
435
436           %params = $q->Vars;  # as a plain hash
437           print $params{'address'};
438           @foo = split "\0", $params{'foo'};
439
440           %params = $q->Vars(','); # specifying a different separator than "\0"
441           @foo = split ',', $params{'foo'};
442
443       Many people want to fetch the entire parameter list as a hash in which
444       the keys are the names of the CGI parameters, and the values are the
445       parameters' values.  The Vars() method does this.
446
447       Called in a scalar context, it returns the parameter list as a tied
448       hash reference. Because this hash ref is tied changing a key/value
449       changes the underlying CGI::Simple object.
450
451       Called in a list context, it returns the parameter list as an ordinary
452       hash.  Changing this hash will not change the underlying CGI::Simple
453       object
454
455       When using Vars(), the thing you must watch out for are multi-valued
456       CGI parameters.  Because a hash cannot distinguish between scalar and
457       list context, multi-valued parameters will be returned as a packed
458       string, separated by the "\0" (null) character.  You must split this
459       packed string in order to get at the individual values.  This is the
460       convention introduced long ago by Steve Brenner in his cgi-lib.pl
461       module for Perl version 4.
462
463       You can change the character used to do the multiple value packing by
464       passing it to Vars() as an argument as shown.
465
466   url_param() Access the QUERY_STRING regardless of 'GET' or 'POST'
467       The url_param() method makes the QUERY_STRING data available regardless
468       of whether the REQUEST_METHOD was 'GET' or 'POST'. You can do anything
469       with url_param that you can do with param(), however the data set is
470       completely independent.
471
472       Technically what happens if you use this method is that the
473       QUERY_STRING data is parsed into a new CGI::Simple object which is
474       stored within the current object. url_param then just calls param() on
475       this new object.
476
477   parse_query_string() Add QUERY_STRING data to 'POST' requests
478       When the REQUEST_METHOD is 'POST' the default behavior is to ignore
479       name/value pairs or keywords in the $ENV{'QUERY_STRING'}. You can
480       override this by calling parse_query_string() which will add the
481       QUERY_STRING data to the data already in our CGI::Simple object if the
482       REQUEST_METHOD was 'POST'
483
484           $q = new CGI::Simple;
485           $q->parse_query_string;  # add $ENV{'QUERY_STRING'} data to our $q object
486
487       If the REQUEST_METHOD was 'GET' then the QUERY_STRING will already be
488       stored in our object so parse_query_string will be ignored.
489
490       This is a new method in CGI::Simple that is not available in CGI.pm
491
492   save() Saving the state of an object to file
493           $q->save(\*FILEHANDLE)
494
495       This will write the current state of the form to the provided
496       filehandle.  You can read it back in by providing a filehandle to the
497       new() method.
498
499       The format of the saved file is:
500
501           NAME1=VALUE1
502           NAME1=VALUE1'
503           NAME2=VALUE2
504           NAME3=VALUE3
505           =
506
507       Both name and value are URL escaped.  Multi-valued CGI parameters are
508       represented as repeated names.  A session record is delimited by a
509       single = symbol.  You can write out multiple records and read them back
510       in with several calls to new().
511
512           open FH, "test.in" or die $!;
513           $q1 = new CGI::Simple(\*FH);  # get the first record
514           $q2 = new CGI::Simple(\*FH);  # get the next record
515
516       Note: If you wish to use this method from the function-oriented (non-
517       OO) interface, the exported name for this method is save_parameters().
518       Also if you want to initialize from a file handle, the way to do this
519       is with restore_parameters().  This will (re)initialize the default
520       CGI::Simple object from the indicated file handle.
521
522           restore_parameters(\*FH);
523

FILE UPLOADS

525       File uploads are easy with CGI::Simple. You use the upload() method.
526       Assuming you have the following in your HTML:
527
528           <FORM
529            METHOD="POST"
530            ACTION="http://somewhere.com/cgi-bin/script.cgi"
531            ENCTYPE="multipart/form-data">
532               <INPUT TYPE="file" NAME="upload_file1" SIZE="42">
533               <INPUT TYPE="file" NAME="upload_file2" SIZE="42">
534           </FORM>
535
536       Note that the ENCTYPE is "multipart/form-data". You must specify this
537       or the browser will default to "application/x-www-form-urlencoded"
538       which will result in no files being uploaded although on the surface
539       things will appear OK.
540
541       When the user submits this form any supplied files will be spooled onto
542       disk and saved in temporary files. These files will be deleted when
543       your script.cgi exits so if you want to keep them you will need to
544       proceed as follows.
545
546   upload() The key file upload method
547       The upload() method is quite versatile. If you call upload() without
548       any arguments it will return a list of uploaded files in list context
549       and the number of uploaded files in scalar context.
550
551           $number_of_files = $q->upload;
552           @list_of_files   = $q->upload;
553
554       Having established that you have uploaded files available you can get
555       the browser supplied filename using param() like this:
556
557           $filename1 = $q->param('upload_file1');
558
559       You can then get a filehandle to read from by calling upload() and
560       supplying this filename as an argument. Warning: do not modify the
561       value you get from param() in any way - you don't need to untaint it.
562
563           $fh = $q->upload( $filename1 );
564
565       Now to save the file you would just do something like:
566
567           $save_path = '/path/to/write/file.name';
568           open FH, ">$save_path" or die "Oops $!\n";
569           binmode FH;
570           print FH $buffer while read( $fh, $buffer, 4096 );
571           close FH;
572
573       By utilizing a new feature of the upload method this process can be
574       simplified to:
575
576           $ok = $q->upload( $q->param('upload_file1'), '/path/to/write/file.name' );
577           if ($ok) {
578               print "Uploaded and wrote file OK!";
579           } else {
580               print $q->cgi_error();
581           }
582
583       As you can see upload will accept an optional second argument and will
584       write the file to this file path. It will return 1 for success and
585       undef if it fails. If it fails you can get the error from cgi_error
586
587       You can also use just the fieldname as an argument to upload ie:
588
589           $fh = $q->upload( 'upload_field_name' );
590
591           or
592
593           $ok = $q->upload( 'upload_field_name', '/path/to/write/file.name' );
594
595       BUT there is a catch. If you have multiple upload fields, all called
596       'upload_field_name' then you will only get the last uploaded file from
597       these fields.
598
599   upload_info() Get the details about uploaded files
600       The upload_info() method is a new method. Called without arguments it
601       returns the number of uploaded files in scalar context and the names of
602       those files in list context.
603
604           $number_of_upload_files   = $q->upload_info();
605           @filenames_of_all_uploads = $q->upload_info();
606
607       You can get the MIME type of an uploaded file like this:
608
609           $mime = $q->upload_info( $filename1, 'mime' );
610
611       If you want to know how big a file is before you copy it you can get
612       that information from uploadInfo which will return the file size in
613       bytes.
614
615           $file_size = $q->upload_info( $filename1, 'size' );
616
617       The size attribute is optional as this is the default value returned.
618
619       Note: The old CGI.pm uploadInfo() method has been deleted.
620
621   $POST_MAX and $DISABLE_UPLOADS
622       CGI.pm has a default setting that allows infinite size file uploads by
623       default. In contrast file uploads are disabled by default in
624       CGI::Simple to discourage Denial of Service attacks. You must enable
625       them before you expect file uploads to work.
626
627       When file uploads are disabled the file name and file size details will
628       still be available from param() and upload_info respectively but the
629       upload filehandle returned by upload() will be undefined - not
630       surprising as the underlying temp file will not exist either.
631
632       You can enable uploads using the '-upload' pragma. You do this by
633       specifying this in you use statement:
634
635           use CGI::Simple qw(-upload);
636
637       Alternatively you can enable uploads via the $DISABLE_UPLOADS global
638       like this:
639
640           use CGI::Simple;
641           $CGI::Simple::DISABLE_UPLOADS = 0;
642           $q = new CGI::Simple;
643
644       If you wish to set $DISABLE_UPLOADS you must do this *after* the use
645       statement and *before* the new constructor call as shown above.
646
647       The maximum acceptable data via post is capped at 102_400kB rather than
648       infinity which is the CGI.pm default. This should be ample for most
649       tasks but you can set this to whatever you want using the $POST_MAX
650       global.
651
652           use CGI::Simple;
653           $CGI::Simple::DISABLE_UPLOADS = 0;      # enable uploads
654           $CGI::Simple::POST_MAX = 1_048_576;     # allow 1MB uploads
655           $q = new CGI::Simple;
656
657       If you set to -1 infinite size uploads will be permitted, which is the
658       CGI.pm default.
659
660           $CGI::Simple::POST_MAX = -1;            # infinite size upload
661
662       Alternatively you can specify all the CGI.pm default values which allow
663       file uploads of infinite size in one easy step by specifying the
664       '-default' pragma in your use statement.
665
666           use CGI::Simple qw( -default ..... );
667
668   binmode() and Win32
669       If you are using CGI::Simple be sure to call binmode() on any handle
670       that you create to write the uploaded file to disk. Calling binmode()
671       will do no harm on other systems anyway.
672

MISCELANEOUS METHODS

674   escapeHTML() Escaping HTML special characters
675       In HTML the < > " and & chars have special meaning and need to be
676       escaped to &lt; &gt; &quot; and &amp; respectively.
677
678           $escaped = $q->escapeHTML( $string );
679
680           $escaped = $q->escapeHTML( $string, 'new_lines_too' );
681
682       If the optional second argument is supplied then newlines will be
683       escaped to.
684
685   unescapeHTML() Unescape HTML special characters
686       This performs the reverse of escapeHTML().
687
688           $unescaped = $q->unescapeHTML( $HTML_escaped_string );
689
690   url_decode() Decode a URL encoded string
691       This method will correctly decode a url encoded string.
692
693           $decoded = $q->url_decode( $encoded );
694
695   url_encode() URL encode a string
696       This method will correctly URL encode a string.
697
698           $encoded = $q->url_encode( $string );
699
700   parse_keywordlist() Parse a supplied keyword list
701           @keywords = $q->parse_keywordlist( $keyword_list );
702
703       This method returns a list of keywords, correctly URL escaped and split
704       out of the supplied string
705
706   put() Send output to browser
707       CGI.pm alias for print. $q->put('Hello World!') will print the usual
708
709   print() Send output to browser
710       CGI.pm alias for print. $q->print('Hello World!') will print the usual
711

HTTP COOKIES

713       CGI.pm has several methods that support cookies.
714
715       A cookie is a name=value pair much like the named parameters in a CGI
716       query string.  CGI scripts create one or more cookies and send them to
717       the browser in the HTTP header.  The browser maintains a list of
718       cookies that belong to a particular Web server, and returns them to the
719       CGI script during subsequent interactions.
720
721       In addition to the required name=value pair, each cookie has several
722       optional attributes:
723
724       1. an expiration time
725           This is a time/date string (in a special GMT format) that indicates
726           when a cookie expires.  The cookie will be saved and returned to
727           your script until this expiration date is reached if the user exits
728           the browser and restarts it.  If an expiration date isn't
729           specified, the cookie will remain active until the user quits the
730           browser.
731
732       2. a domain
733           This is a partial or complete domain name for which the cookie is
734           valid.  The browser will return the cookie to any host that matches
735           the partial domain name.  For example, if you specify a domain name
736           of ".capricorn.com", then the browser will return the cookie to Web
737           servers running on any of the machines "www.capricorn.com",
738           "www2.capricorn.com", "feckless.capricorn.com", etc.  Domain names
739           must contain at least two periods to prevent attempts to match on
740           top level domains like ".edu".  If no domain is specified, then the
741           browser will only return the cookie to servers on the host the
742           cookie originated from.
743
744       3. a path
745           If you provide a cookie path attribute, the browser will check it
746           against your script's URL before returning the cookie.  For
747           example, if you specify the path "/cgi-bin", then the cookie will
748           be returned to each of the scripts "/cgi-bin/tally.pl",
749           "/cgi-bin/order.pl", and "/cgi-bin/customer_service/complain.pl",
750           but not to the script "/cgi-private/site_admin.pl".  By default,
751           path is set to "/", which causes the cookie to be sent to any CGI
752           script on your site.
753
754       4. a "secure" flag
755           If the "secure" attribute is set, the cookie will only be sent to
756           your script if the CGI request is occurring on a secure channel,
757           such as SSL.
758
759   cookie() A simple access method to cookies
760       The interface to HTTP cookies is the cookie() method:
761
762           $cookie = $q->cookie( -name      => 'sessionID',
763                                 -value     => 'xyzzy',
764                                 -expires   => '+1h',
765                                 -path      => '/cgi-bin/database',
766                                 -domain    => '.capricorn.org',
767                                 -secure    => 1
768                                );
769           print $q->header(-cookie=>$cookie);
770
771       cookie() creates a new cookie.  Its parameters include:
772
773       -name
774           The name of the cookie (required).  This can be any string at all.
775           Although browsers limit their cookie names to non-whitespace
776           alphanumeric characters, CGI.pm removes this restriction by
777           escaping and unescaping cookies behind the scenes.
778
779       -value
780           The value of the cookie.  This can be any scalar value, array
781           reference, or even associative array reference.  For example, you
782           can store an entire associative array into a cookie this way:
783
784               $cookie=$q->cookie( -name   => 'family information',
785                                   -value  => \%childrens_ages );
786
787       -path
788           The optional partial path for which this cookie will be valid, as
789           described above.
790
791       -domain
792           The optional partial domain for which this cookie will be valid, as
793           described above.
794
795       -expires
796           The optional expiration date for this cookie.  The format is as
797           described in the section on the header() method:
798
799               "+1h"  one hour from now
800
801       -secure
802           If set to true, this cookie will only be used within a secure SSL
803           session.
804
805       The cookie created by cookie() must be incorporated into the HTTP
806       header within the string returned by the header() method:
807
808           print $q->header(-cookie=>$my_cookie);
809
810       To create multiple cookies, give header() an array reference:
811
812           $cookie1 = $q->cookie( -name  => 'riddle_name',
813                                  -value => "The Sphynx's Question"
814                                );
815           $cookie2 = $q->cookie( -name  => 'answers',
816                                  -value => \%answers
817                                );
818           print $q->header( -cookie => [ $cookie1, $cookie2 ] );
819
820       To retrieve a cookie, request it by name by calling cookie() method
821       without the -value parameter:
822
823           use CGI::Simple;
824           $q = new CGI::Simple;
825           $riddle  = $q->cookie('riddle_name');
826           %answers = $q->cookie('answers');
827
828       Cookies created with a single scalar value, such as the "riddle_name"
829       cookie, will be returned in that form.  Cookies with array and hash
830       values can also be retrieved.
831
832       The cookie and CGI::Simple  namespaces are separate.  If you have a
833       parameter named 'answers' and a cookie named 'answers', the values
834       retrieved by param() and cookie() are independent of each other.
835       However, it's simple to turn a CGI parameter into a cookie, and vice-
836       versa:
837
838           # turn a CGI parameter into a cookie
839           $c = $q->cookie( -name=>'answers', -value=>[$q->param('answers')] );
840           # vice-versa
841           $q->param( -name=>'answers', -value=>[$q->cookie('answers')] );
842
843   raw_cookie()
844       Returns the HTTP_COOKIE variable. Cookies have a special format, and
845       this method call just returns the raw form (?cookie dough). See
846       cookie() for ways of setting and retrieving cooked cookies.
847
848       Called with no parameters, raw_cookie() returns the packed cookie
849       structure.  You can separate it into individual cookies by splitting on
850       the character sequence "; ".  Called with the name of a cookie,
851       retrieves the unescaped form of the cookie.  You can use the regular
852       cookie() method to get the names, or use the raw_fetch() method from
853       the CGI::Simmple::Cookie module.
854

CREATING HTTP HEADERS

856       Normally the first thing you will do in any CGI script is print out an
857       HTTP header.  This tells the browser what type of document to expect,
858       and gives other optional information, such as the language, expiration
859       date, and whether to cache the document.  The header can also be
860       manipulated for special purposes, such as server push and pay per view
861       pages.
862
863   header() Create simple or complex HTTP headers
864           print $q->header;
865
866                -or-
867
868           print $q->header('image/gif');
869
870                -or-
871
872           print $q->header('text/html','204 No response');
873
874                -or-
875
876           print $q->header( -type       => 'image/gif',
877                             -nph        => 1,
878                             -status     => '402 Payment required',
879                             -expires    => '+3d',
880                             -cookie     => $cookie,
881                             -charset    => 'utf-7',
882                             -attachment => 'foo.gif',
883                             -Cost       => '$2.00'
884                           );
885
886       header() returns the Content-type: header.  You can provide your own
887       MIME type if you choose, otherwise it defaults to text/html.  An
888       optional second parameter specifies the status code and a human-
889       readable message.  For example, you can specify 204, "No response" to
890       create a script that tells the browser to do nothing at all.
891
892       The last example shows the named argument style for passing arguments
893       to the CGI methods using named parameters.  Recognized parameters are
894       -type, -status, -cookie, -target, -expires, -nph, -charset and
895       -attachment.  Any other named parameters will be stripped of their
896       initial hyphens and turned into header fields, allowing you to specify
897       any HTTP header you desire.
898
899       For example, you can produce non-standard HTTP header fields by
900       providing them as named arguments:
901
902         print $q->header( -type            => 'text/html',
903                           -nph             => 1,
904                           -cost            => 'Three smackers',
905                           -annoyance_level => 'high',
906                           -complaints_to   => 'bit bucket'
907                         );
908
909       This will produce the following non-standard HTTP header:
910
911           HTTP/1.0 200 OK
912           Cost: Three smackers
913           Annoyance-level: high
914           Complaints-to: bit bucket
915           Content-type: text/html
916
917       Note that underscores are translated automatically into hyphens. This
918       feature allows you to keep up with the rapidly changing HTTP
919       "standards".
920
921       The -type is a key element that tell the browser how to display your
922       document. The default is 'text/html'. Common types are:
923
924           text/html
925           text/plain
926           image/gif
927           image/jpg
928           image/png
929           application/octet-stream
930
931       The -status code is the HTTP response code. The default is 200 OK.
932       Common status codes are:
933
934           200 OK
935           204 No Response
936           301 Moved Permanently
937           302 Found
938           303 See Other
939           307 Temporary Redirect
940           400 Bad Request
941           401 Unauthorized
942           403 Forbidden
943           404 Not Found
944           405 Not Allowed
945           408 Request Timed Out
946           500 Internal Server Error
947           503 Service Unavailable
948           504 Gateway Timed Out
949
950       The -expires parameter lets you indicate to a browser and proxy server
951       how long to cache pages for. When you specify an absolute or relative
952       expiration interval with this parameter, some browsers and proxy
953       servers will cache the script's output until the indicated expiration
954       date.  The following forms are all valid for the -expires field:
955
956           +30s                                30 seconds from now
957           +10m                                ten minutes from now
958           +1h                                 one hour from now
959           -1d                                 yesterday (i.e. "ASAP!")
960           now                                 immediately
961           +3M                                 in three months
962           +10y                                in ten years time
963           Thursday, 25-Apr-1999 00:40:33 GMT  at the indicated time & date
964
965       The -cookie parameter generates a header that tells the browser to
966       provide a "magic cookie" during all subsequent transactions with your
967       script.  Netscape cookies have a special format that includes
968       interesting attributes such as expiration time.  Use the cookie()
969       method to create and retrieve session cookies.
970
971       The -target is for frames use
972
973       The -nph parameter, if set to a true value, will issue the correct
974       headers to work with a NPH (no-parse-header) script.  This is important
975       to use with certain servers that expect all their scripts to be NPH.
976
977       The -charset parameter can be used to control the character set sent to
978       the browser.  If not provided, defaults to ISO-8859-1.  As a side
979       effect, this sets the charset() method as well.
980
981       The -attachment parameter can be used to turn the page into an
982       attachment.  Instead of displaying the page, some browsers will prompt
983       the user to save it to disk.  The value of the argument is the
984       suggested name for the saved file.  In order for this to work, you may
985       have to set the -type to 'application/octet-stream'.
986
987   no_cache() Preventing browser caching of scripts
988       Most browsers will not cache the output from CGI scripts. Every time
989       the browser reloads the page, the script is invoked anew. However some
990       browsers do cache pages. You can discourage this behavior using the
991       no_cache() function.
992
993           $q->no_cache(1); # turn caching off by sending appropriate headers
994           $q->no_cache(1); # do not send cache related headers.
995
996           $q->no_cache(1);
997           print header (-type=>'image/gif', -nph=>1);
998
999           This will produce a header like the following:
1000
1001           HTTP/1.0 200 OK
1002           Server: Apache - accept no substitutes
1003           Expires: Thu, 15 Nov 2001 03:37:50 GMT
1004           Date: Thu, 15 Nov 2001 03:37:50 GMT
1005           Pragma: no-cache
1006           Content-Type: image/gif
1007
1008       Both the Pragma: no-cache header field and an Expires header that
1009       corresponds to the current time (ie now) will be sent.
1010
1011   cache() Preventing browser caching of scripts
1012       The somewhat ill named cache() method is a legacy from CGI.pm. It
1013       operates the same as the new no_cache() method. The difference is/was
1014       that when set it results only in the Pragma: no-cache line being
1015       printed.  Expires time data is not sent.
1016
1017   redirect() Generating a redirection header
1018           print $q->redirect('http://somewhere.else/in/movie/land');
1019
1020       Sometimes you don't want to produce a document yourself, but simply
1021       redirect the browser elsewhere, perhaps choosing a URL based on the
1022       time of day or the identity of the user.
1023
1024       The redirect() function redirects the browser to a different URL.  If
1025       you use redirection like this, you should not print out a header as
1026       well.
1027
1028       One hint I can offer is that relative links may not work correctly when
1029       you generate a redirection to another document on your site.  This is
1030       due to a well-intentioned optimization that some servers use.  The
1031       solution to this is to use the full URL (including the http: part) of
1032       the document you are redirecting to.
1033
1034       You can also use named arguments:
1035
1036           print $q->redirect( -uri=>'http://somewhere.else/in/movie/land',
1037                               -nph=>1
1038                             );
1039
1040       The -nph parameter, if set to a true value, will issue the correct
1041       headers to work with a NPH (no-parse-header) script.  This is important
1042       to use with certain servers, such as Microsoft ones, which expect all
1043       their scripts to be NPH.
1044

PRAGMAS

1046       There are a number of pragmas that you can specify in your use
1047       CGI::Simple statement. Pragmas, which are always preceded by a hyphen,
1048       change the way that CGI::Simple functions in various ways. You can
1049       generally achieve exactly the same results by setting the underlying
1050       $GLOBAL_VARIABLES.
1051
1052       For example the '-upload' pargma will enable file uploads:
1053
1054           use CGI::Simple qw(-upload);
1055
1056       In CGI::Simple::Standard Pragmas, function sets , and individual
1057       functions can all be imported in the same use() line.  For example, the
1058       following use statement imports the standard set of functions and
1059       enables debugging mode (pragma -debug):
1060
1061           use CGI::Simple::Standard qw(:standard -debug);
1062
1063       The current list of pragmas is as follows:
1064
1065       -no_undef_params
1066           If a value is not given in the query string, as in the queries
1067           "name1=&name2=" or "name1&name2", by default it will be returned as
1068           an empty string.
1069
1070           If you specify the '-no_undef_params' pragma then CGI::Simple
1071           ignores parameters with no values and they will not appear in the
1072           query object.
1073
1074       -nph
1075           This makes CGI.pm produce a header appropriate for an NPH (no
1076           parsed header) script.  You may need to do other things as well to
1077           tell the server that the script is NPH.  See the discussion of NPH
1078           scripts below.
1079
1080       -newstyle_urls
1081           Separate the name=value pairs in CGI parameter query strings with
1082           semicolons rather than ampersands.  For example:
1083
1084               ?name=fred;age=24;favorite_color=3
1085
1086           Semicolon-delimited query strings are always accepted, but will not
1087           be emitted by self_url() and query_string() unless the
1088           -newstyle_urls pragma is specified.
1089
1090       -oldstyle_urls
1091           Separate the name=value pairs in CGI parameter query strings with
1092           ampersands rather than semicolons.  This is the default.
1093
1094               ?name=fred&age=24&favorite_color=3
1095
1096       -autoload
1097           This is only available for CGI::Simple::Standard and uses AUTOLOAD
1098           to load functions on demand. See the CGI::Simple::Standard docs for
1099           details.
1100
1101       -no_debug
1102           This turns off the command-line processing features. This is the
1103           default.
1104
1105       -debug1 and debug2
1106           This turns on debugging.  At debug level 1 CGI::Simple will read
1107           arguments from the command-line. At debug level 2 CGI.pm will
1108           produce the prompt "(offline mode: enter name=value pairs on
1109           standard input)" and wait for input on STDIN. If no number is
1110           specified then a debug level of 2 is used.
1111
1112           See the section on debugging for more details.
1113
1114       -default
1115           This sets the default global values for CGI.pm which will enable
1116           infinite size file uploads, and specify the '-newstyle_urls' and
1117           '-debug1' pragmas
1118
1119       -no_upload
1120           Disable uploads - the default setting
1121
1122       - upload
1123           Enable uploads - the CGI.pm default
1124
1125       -unique_header
1126           Only allows headers to be generated once per script invocation
1127
1128       -carp
1129           Carp when cgi_error() called, default is to do nothing
1130
1131       -croak
1132           Croak when cgi_error() called, default is to do nothing
1133

USING NPH SCRIPTS

1135       NPH, or "no-parsed-header", scripts bypass the server completely by
1136       sending the complete HTTP header directly to the browser.  This has
1137       slight performance benefits, but is of most use for taking advantage of
1138       HTTP extensions that are not directly supported by your server, such as
1139       server push and PICS headers.
1140
1141       Servers use a variety of conventions for designating CGI scripts as
1142       NPH.  Many Unix servers look at the beginning of the script's name for
1143       the prefix "nph-".  The Macintosh WebSTAR server and Microsoft's
1144       Internet Information Server, in contrast, try to decide whether a
1145       program is an NPH script by examining the first line of script output.
1146
1147       CGI.pm supports NPH scripts with a special NPH mode.  When in this
1148       mode, CGI.pm will output the necessary extra header information when
1149       the header() and redirect() methods are called. You can set NPH mode in
1150       any of the following ways:
1151
1152       In the use statement
1153           Simply add the "-nph" pragma to the use:
1154
1155               use CGI::Simple qw(-nph)
1156
1157       By calling the nph() method:
1158           Call nph() with a non-zero parameter at any point after using
1159           CGI.pm in your program.
1160
1161               $q->nph(1)
1162
1163       By using -nph parameters
1164           in the header() and redirect()  statements:
1165
1166               print $q->header(-nph=>1);
1167
1168       The Microsoft Internet Information Server requires NPH mode.
1169       CGI::Simple will automatically detect when the script is running under
1170       IIS and put itself into this mode.  You do not need to do this
1171       manually, although it won't hurt anything if you do.  However, note
1172       that if you have applied Service Pack 6, much of the functionality of
1173       NPH scripts, including the ability to redirect while setting a cookie,
1174       b<do not work at all> on IIS without a special patch from Microsoft.
1175       See http://support.microsoft.com/support/kb/articles/Q280/3/41.ASP:
1176       Non-Parsed Headers Stripped From CGI Applications That Have nph- Prefix
1177       in Name.
1178

SERVER PUSH

1180       CGI.pm provides four simple functions for producing multipart documents
1181       of the type needed to implement server push.  These functions were
1182       graciously provided by Ed Jordan <ed@fidalgo.net> with additions from
1183       Andrew Benham <adsb@bigfoot.com>
1184
1185       You are also advised to put the script into NPH mode and to set $| to 1
1186       to avoid buffering problems.
1187
1188       Browser support for server push is variable.
1189
1190       Here is a simple script that demonstrates server push:
1191
1192           #!/usr/local/bin/perl
1193           use CGI::Simple::Standard qw/:push -nph/;
1194           $| = 1;
1195           print multipart_init(-boundary=>'----here we go!');
1196           foreach (0 .. 4) {
1197               print multipart_start(-type=>'text/plain'),
1198               "The current time is ",scalar(localtime),"\n";
1199               if ($_ < 4) {
1200                   print multipart_end;
1201               }
1202               else {
1203                   print multipart_final;
1204               }
1205               sleep 1;
1206           }
1207
1208       This script initializes server push by calling multipart_init().  It
1209       then enters a loop in which it begins a new multipart section by
1210       calling multipart_start(), prints the current local time, and ends a
1211       multipart section with multipart_end().  It then sleeps a second, and
1212       begins again. On the final iteration, it ends the multipart section
1213       with multipart_final() rather than with multipart_end().
1214
1215   multipart_init() Initialize the multipart system
1216           multipart_init(-boundary=>$boundary);
1217
1218       Initialize the multipart system.  The -boundary argument specifies what
1219       MIME boundary string to use to separate parts of the document.  If not
1220       provided, CGI.pm chooses a reasonable boundary for you.
1221
1222   multipart_start() Start a new part of the multipart document
1223           multipart_start(-type=>$type)
1224
1225       Start a new part of the multipart document using the specified MIME
1226       type.  If not specified, text/html is assumed.
1227
1228   multipart_end() End a multipart part
1229           multipart_end()
1230
1231       End a part.  You must remember to call multipart_end() once for each
1232       multipart_start(), except at the end of the last part of the multipart
1233       document when multipart_final() should be called instead of
1234       multipart_end().
1235
1236   multipart_final()
1237           multipart_final()
1238
1239       End all parts.  You should call multipart_final() rather than
1240       multipart_end() at the end of the last part of the multipart document.
1241
1242   CGI::Push
1243       Users interested in server push applications should also have a look at
1244       the CGI::Push module.
1245

DEBUGGING

1247       If you are running the script from the command line or in the perl
1248       debugger, you can pass the script a list of keywords or parameter=value
1249       pairs on the command line or from standard input (you don't have to
1250       worry about tricking your script into reading from environment
1251       variables).  Before you do this you will need to change the debug level
1252       from the default level of 0 (no debug) to either 1 if you want to debug
1253       from @ARGV (the command line) of 2 if you want to debug from STDIN. You
1254       can do this using the debug pragma like this:
1255
1256           use CGI::Simple qw(-debug2);  # set debug to level 2 => from STDIN
1257
1258               or this:
1259
1260           $CGI::Simple::DEBUG = 1;      # set debug to level 1 => from @ARGV
1261
1262       At debug level 1 you can pass keywords and name=value pairs like this:
1263
1264           your_script.pl keyword1 keyword2 keyword3
1265
1266               or this:
1267
1268           your_script.pl keyword1+keyword2+keyword3
1269
1270               or this:
1271
1272           your_script.pl name1=value1 name2=value2
1273
1274               or this:
1275
1276           your_script.pl name1=value1&name2=value2
1277
1278       At debug level 2 you can feed newline-delimited name=value pairs to the
1279       script on standard input. You will be presented with the following
1280       prompt:
1281
1282           (offline mode: enter name=value pairs on standard input)
1283
1284       You end the input with your system dependent end of file character.
1285       You should try ^Z ^X ^D and ^C if all else fails. The ^ means hold down
1286       the [Ctrl] button while you press the other key.
1287
1288       When debugging, you can use quotes and backslashes to escape characters
1289       in the familiar shell manner, letting you place spaces and other funny
1290       characters in your parameter=value pairs:
1291
1292           your_script.pl "name1='I am a long value'" "name2=two\ words"
1293
1294   Dump() Dumping the current object details
1295       The Dump() method produces a string consisting of all the query's
1296       object attributes formatted nicely as a nested list.  This dump
1297       includes the name/value pairs and a number of other details. This is
1298       useful for debugging purposes:
1299
1300           print $q->Dump
1301
1302       The actual result of this is HTML escaped formatted text wrapped in
1303       <pre> tags so if you send it straight to the browser it produces
1304       something that looks like:
1305
1306           $VAR1 = bless( {
1307                '.parameters' => [
1308                                   'name',
1309                                   'color'
1310                                 ],
1311                '.globals' => {
1312                                'FATAL' => -1,
1313                                'DEBUG' => 0,
1314                                'NO_NULL' => 1,
1315                                'POST_MAX' => 102400,
1316                                'USE_CGI_PM_DEFAULTS' => 0,
1317                                'HEADERS_ONCE' => 0,
1318                                'NPH' => 0,
1319                                'DISABLE_UPLOADS' => 1,
1320                                'NO_UNDEF_PARAMS' => 0,
1321                                'USE_PARAM_SEMICOLONS' => 0
1322                              },
1323                '.fieldnames' => {
1324                                   'color' => '1',
1325                                   'name' => '1'
1326                                 },
1327                '.mod_perl' => '',
1328                'color' => [
1329                             'red',
1330                             'green',
1331                             'blue'
1332                           ],
1333                'name' => [
1334                            'JaPh,'
1335                          ]
1336               }, 'CGI::Simple' );
1337
1338       You may recognize this as valid Perl syntax (which it is) and/or the
1339       output from Data::Dumper (also true). This is the actual guts of how
1340       the information is stored in the query object. All the internal params
1341       start with a . char
1342
1343       Alternatively you can dump your object and the current environment
1344       using:
1345
1346           print $q->Dump(\%ENV);
1347
1348   PrintEnv() Dumping the environment
1349       You can get a similar browser friendly dump of the current %ENV hash
1350       using:
1351
1352           print $q->PrintEnv;
1353
1354       This will produce something like (in the browser):
1355
1356           $VAR1 = {
1357                 'QUERY_STRING' => 'name=JaPh%2C&color=red&color=green&color=blue',
1358                 'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
1359                 'REGRESSION_TEST' => 'simple.t.pl',
1360                 'VIM' => 'C:\\WINDOWS\\Desktop\\vim',
1361                 'HTTP_REFERER' => 'xxx.sex.com',
1362                 'HTTP_USER_AGENT' => 'LWP',
1363                 'HTTP_ACCEPT' => 'text/html;q=1, image/gif;q=0.42, */*;q=0.001',
1364                 'REMOTE_HOST' => 'localhost',
1365                 'HTTP_HOST' => 'the.restaurant.at.the.end.of.the.universe',
1366                 'GATEWAY_INTERFACE' => 'bleeding edge',
1367                 'REMOTE_IDENT' => 'None of your damn business',
1368                 'SCRIPT_NAME' => '/cgi-bin/foo.cgi',
1369                 'SERVER_NAME' => 'nowhere.com',
1370                 'HTTP_COOKIE' => '',
1371                 'CONTENT_LENGTH' => '42',
1372                 'HTTPS_A' => 'A',
1373                 'HTTP_FROM' => 'spammer@nowhere.com',
1374                 'HTTPS_B' => 'B',
1375                 'SERVER_PROTOCOL' => 'HTTP/1.0',
1376                 'PATH_TRANSLATED' => '/usr/local/somewhere/else',
1377                 'SERVER_SOFTWARE' => 'Apache - accept no substitutes',
1378                 'PATH_INFO' => '/somewhere/else',
1379                 'REMOTE_USER' => 'Just another Perl hacker,',
1380                 'REMOTE_ADDR' => '127.0.0.1',
1381                 'HTTPS' => 'ON',
1382                 'DOCUMENT_ROOT' => '/vs/www/foo',
1383                 'REQUEST_METHOD' => 'GET',
1384                 'REDIRECT_QUERY_STRING' => '',
1385                 'AUTH_TYPE' => 'PGP MD5 DES rot13',
1386                 'COOKIE' => 'foo=a%20phrase; bar=yes%2C%20a%20phrase&;I%20say;',
1387                 'SERVER_PORT' => '8080'
1388               };
1389
1390   cgi_error() Retrieving CGI::Simple error messages
1391       Errors can occur while processing user input, particularly when
1392       processing uploaded files.  When these errors occur, CGI::Simple will
1393       stop processing and return an empty parameter list.  You can test for
1394       the existence and nature of errors using the cgi_error() function.  The
1395       error messages are formatted as HTTP status codes. You can either
1396       incorporate the error text into an HTML page, or use it as the value of
1397       the HTTP status:
1398
1399           my $error = $q->cgi_error;
1400           if ($error) {
1401               print $q->header(-status=>$error);
1402               print "<H2>$error</H2>;
1403             exit;
1404           }
1405

ACCESSOR METHODS

1407   version() Get the CGI::Simple version info
1408           $version = $q->version();
1409
1410       The version() method returns the value of $VERSION
1411
1412   nph() Enable/disable NPH (Non Parsed Header) mode
1413           $q->nph(1);  # enable NPH mode
1414           $q->nph(0);  # disable NPH mode
1415
1416       The nph() method enables and disables NPH headers. See the NPH section.
1417
1418   all_parameters() Get the names/values of all parameters
1419           @all_parameters = $q->all_parameters();
1420
1421       The all_parameters() method is an alias for param()
1422
1423   charset() Get/set the current character set.
1424           $charset = $q->charset(); # get current charset
1425           $q->charset('utf-42');    # set the charset
1426
1427       The charset() method gets the current charset value if no argument is
1428       supplied or sets it if an argument is supplied.
1429
1430   crlf() Get the system specific line ending sequence
1431           $crlf = $q->crlf();
1432
1433       The crlf() method returns the system specific line ending sequence.
1434
1435   globals() Get/set the value of the remaining global variables
1436           $globals = $q->globals('FATAL');     # get the current value of $FATAL
1437           $globals = $q->globals('FATAL', 1 ); # set croak mode on cgi_error()
1438
1439       The globals() method gets/sets the values of the global variables after
1440       the script has been invoked. For globals like $POST_MAX and
1441       $DISABLE_UPLOADS this makes no difference as they must be set prior to
1442       calling the new constructor but there might be reason the change the
1443       value of others.
1444
1445   auth_type() Get the current authorization/verification method
1446           $auth_type = $q->auth_type();
1447
1448       The auth_type() method returns the value of $ENV{'AUTH_TYPE'} which
1449       should contain the authorization/verification method in use for this
1450       script, if any.
1451
1452   content_length() Get the content length submitted in a POST
1453           $content_length = $q->content_length();
1454
1455       The content_length() method returns the value of $ENV{'AUTH_TYPE'}
1456
1457   content_type() Get the content_type of data submitted in a POST
1458           $content_type = $q->content_type();
1459
1460       The content_type() method returns the content_type of data submitted in
1461       a POST, generally 'multipart/form-data' or
1462       'application/x-www-form-urlencoded' as supplied in $ENV{'CONTENT_TYPE'}
1463
1464   document_root() Get the document root
1465           $document_root = $q->document_root();
1466
1467       The document_root() method returns the value of $ENV{'DOCUMENT_ROOT'}
1468
1469   gateway_interface() Get the gateway interface
1470           $gateway_interface = $q->gateway_interface();
1471
1472       The gateway_interface() method returns the value of
1473       $ENV{'GATEWAY_INTERFACE'}
1474
1475   path_translated() Get the value of path translated
1476           $path_translated = $q->path_translated();
1477
1478       The path_translated() method returns the value of
1479       $ENV{'PATH_TRANSLATED'}
1480
1481   referer() Spy on your users
1482           $referer = $q->referer();
1483
1484       The referer() method returns the value of $ENV{'REFERER'} This will
1485       return the URL of the page the browser was viewing prior to fetching
1486       your script.  Not available for all browsers.
1487
1488   remote_addr() Get the remote address
1489           $remote_addr = $q->remote_addr();
1490
1491       The remote_addr() method returns the value of $ENV{'REMOTE_ADDR'} or
1492       127.0.0.1 (localhost) if this is not defined.
1493
1494   remote_host() Get a value for remote host
1495           $remote_host = $q->remote_host();
1496
1497       The remote_host() method returns the value of $ENV{'REMOTE_HOST'} if it
1498       is defined. If this is not defined it returns $ENV{'REMOTE_ADDR'} If
1499       this is not defined it returns 'localhost'
1500
1501   remote_ident() Get the remote identity
1502           $remote_ident = $q->remote_ident();
1503
1504       The remote_ident() method returns the value of $ENV{'REMOTE_IDENT'}
1505
1506   remote_user() Get the remote user
1507           $remote_user = $q->remote_user();
1508
1509       The remote_user() method returns the authorization/verification name
1510       used for user verification, if this script is protected. The value
1511       comes from $ENV{'REMOTE_USER'}
1512
1513   request_method() Get the request method
1514           $request_method = $q->request_method();
1515
1516       The request_method() method returns the method used to access your
1517       script, usually one of 'POST', 'GET' or 'HEAD' as supplied by
1518       $ENV{'REQUEST_METHOD'}
1519
1520   script_name() Get the script name
1521           $script_name = $q->script_name();
1522
1523       The script_name() method returns the value of $ENV{'SCRIPT_NAME'} if it
1524       is defined. Otherwise it returns Perl's script name from $0. Failing
1525       this it returns a null string ''
1526
1527   server_name() Get the server name
1528           $server_name = $q->server_name();
1529
1530       The server_name() method returns the value of $ENV{'SERVER_NAME'} if
1531       defined or 'localhost' otherwise
1532
1533   server_port() Get the port the server is listening on
1534           $server_port = $q->server_port();
1535
1536       The server_port() method returns the value $ENV{'SERVER_PORT'} if
1537       defined or 80 if not.
1538
1539   server_protocol() Get the current server protocol
1540           $server_protocol = $q->server_protocol();
1541
1542       The server_protocol() method returns the value of
1543       $ENV{'SERVER_PROTOCOL'} if defined or 'HTTP/1.0' otherwise
1544
1545   server_software() Get the server software
1546           $server_software = $q->server_software();
1547
1548       The server_software() method returns the value $ENV{'SERVER_SOFTWARE'}
1549       or 'cmdline' If the server software is IIS it formats your hard drive,
1550       installs Linux, FTPs to www.apache.org, installs Apache, and then
1551       restores your system from tape. Well maybe not, but it's a nice
1552       thought.
1553
1554   user_name() Get a value for the user name.
1555           $user_name = $q->user_name();
1556
1557       Attempt to obtain the remote user's name, using a variety of different
1558       techniques.  This only works with older browsers such as Mosaic.  Newer
1559       browsers do not report the user name for privacy reasons!
1560
1561       Technically the user_name() method returns the value of
1562       $ENV{'HTTP_FROM'} or failing that $ENV{'REMOTE_IDENT'} or as a last
1563       choice $ENV{'REMOTE_USER'}
1564
1565   user_agent() Get the users browser type
1566           $ua = $q->user_agent();          # return the user agent
1567           $ok = $q->user_agent('mozilla'); # return true if user agent 'mozilla'
1568
1569       The user_agent() method returns the value of $ENV{'HTTP_USER_AGENT'}
1570       when called without an argument or true or false if the
1571       $ENV{'HTTP_USER_AGENT'} matches the passed argument. The matching is
1572       case insensitive and partial.
1573
1574   virtual_host() Get the virtual host
1575           $virtual_host = $q->virtual_host();
1576
1577       The virtual_host() method returns the value of  $ENV{'HTTP_HOST'} if
1578       defined or $ENV{'SERVER_NAME'} as a default. Port numbers are removed.
1579
1580   path_info() Get any extra path info set to the script
1581           $path_info = $q->path_info();
1582
1583       The path_info() method returns additional path information from the
1584       script URL. E.G. fetching /cgi-bin/your_script/additional/stuff will
1585       result in $q->path_info() returning "/additional/stuff".
1586
1587       NOTE: The Microsoft Internet Information Server is broken with respect
1588       to additional path information.  If you use the Perl DLL library, the
1589       IIS server will attempt to execute the additional path information as a
1590       Perl script.  If you use the ordinary file associations mapping, the
1591       path information will be present in the environment, but incorrect.
1592       The best thing to do is to avoid using additional path information in
1593       CGI scripts destined for use with IIS.
1594
1595   Accept() Get the browser MIME types
1596           $Accept = $q->Accept();
1597
1598       The Accept() method returns a list of MIME types that the remote
1599       browser accepts. If you give this method a single argument
1600       corresponding to a MIME type, as in $q->Accept('text/html'), it will
1601       return a floating point value corresponding to the browser's preference
1602       for this type from 0.0 (don't want) to 1.0.  Glob types (e.g. text/*)
1603       in the browser's accept list are handled correctly.
1604
1605   accept() Alias for Accept()
1606           $accept = $q->accept();
1607
1608       The accept() Method is an alias for Accept()
1609
1610   http() Get a range of HTTP related information
1611           $http = $q->http();
1612
1613       Called with no arguments the http() method returns the list of HTTP or
1614       HTTPS environment variables, including such things as HTTP_USER_AGENT,
1615       HTTP_ACCEPT_LANGUAGE, and HTTP_ACCEPT_CHARSET, corresponding to the
1616       like-named HTTP header fields in the request. Called with the name of
1617       an HTTP header field, returns its value.  Capitalization and the use of
1618       hyphens versus underscores are not significant.
1619
1620       For example, all three of these examples are equivalent:
1621
1622          $requested_language = $q->http('Accept-language');
1623          $requested_language = $q->http('Accept_language');
1624          $requested_language = $q->http('HTTP_ACCEPT_LANGUAGE');
1625
1626   https() Get a range of HTTPS related information
1627           $https = $q->https();
1628
1629       The https() method is similar to the http() method except that when
1630       called without an argument it returns the value of $ENV{'HTTPS'} which
1631       will be true if a HTTPS connection is in use and false otherwise.
1632
1633   protocol() Get the current protocol
1634           $protocol = $q->protocol();
1635
1636       The protocol() method returns 'https' if a HTTPS connection is in use
1637       or the server_protocol() minus version numbers ('http') otherwise.
1638
1639   url() Return the script's URL in several formats
1640           $full_url      = $q->url();
1641           $full_url      = $q->url(-full=>1);
1642           $relative_url  = $q->url(-relative=>1);
1643           $absolute_url  = $q->url(-absolute=>1);
1644           $url_with_path = $q->url(-path_info=>1);
1645           $url_with_path_and_query = $q->url(-path_info=>1,-query=>1);
1646           $netloc        = $q->url(-base => 1);
1647
1648       url() returns the script's URL in a variety of formats.  Called without
1649       any arguments, it returns the full form of the URL, including host name
1650       and port number
1651
1652           http://your.host.com/path/to/script.cgi
1653
1654       You can modify this format with the following named arguments:
1655
1656       -absolute
1657           If true, produce an absolute URL, e.g.
1658
1659               /path/to/script.cgi
1660
1661       -relative
1662           Produce a relative URL.  This is useful if you want to reinvoke
1663           your script with different parameters. For example:
1664
1665               script.cgi
1666
1667       -full
1668           Produce the full URL, exactly as if called without any arguments.
1669           This overrides the -relative and -absolute arguments.
1670
1671       -path (-path_info)
1672           Append the additional path information to the URL.  This can be
1673           combined with -full, -absolute or -relative.  -path_info is
1674           provided as a synonym.
1675
1676       -query (-query_string)
1677           Append the query string to the URL.  This can be combined with
1678           -full, -absolute or -relative.  -query_string is provided as a
1679           synonym.
1680
1681       -base
1682           Generate just the protocol and net location, as in
1683           http://www.foo.com:8000
1684
1685   self_url() Get the scripts complete URL
1686           $self_url = $q->self_url();
1687
1688       The self_url() method returns the value of:
1689
1690          $self->url( '-path_info'=>1, '-query'=>1, '-full'=>1 );
1691
1692   state() Alias for self_url()
1693           $state = $q->state();
1694
1695       The state() method is an alias for self_url()
1696

COMPATIBILITY WITH cgi-lib.pl 2.18

1698       To make it easier to port existing programs that use cgi-lib.pl all the
1699       subs within cgi-lib.pl are available in CGI::Simple.  Using the
1700       functional interface of CGI::Simple::Standard porting is as easy as:
1701
1702           OLD VERSION
1703               require "cgi-lib.pl";
1704               &ReadParse;
1705               print "The value of the antique is $in{'antique'}.\n";
1706
1707           NEW VERSION
1708               use CGI::Simple::Standard qw(:cgi-lib);
1709               &ReadParse;
1710               print "The value of the antique is $in{'antique'}.\n";
1711
1712       CGI:Simple's ReadParse() routine creates a variable named %in, which
1713       can be accessed to obtain the query variables.  Like ReadParse, you can
1714       also provide your own variable via a glob. Infrequently used features
1715       of ReadParse(), such as the creation of @in and $in variables, are not
1716       supported.
1717
1718       You can also use the OO interface of CGI::Simple and call ReadParse()
1719       and other cgi-lib.pl functions like this:
1720
1721           &CGI::Simple::ReadParse;       # get hash values in %in
1722
1723           my $q = new CGI::Simple;
1724           $q->ReadParse();                # same thing
1725
1726           CGI::Simple::ReadParse(*field); # get hash values in %field function style
1727
1728           my $q = new CGI::Simple;
1729           $q->ReadParse(*field);          # same thing
1730
1731       Once you use ReadParse() under the functional interface , you can
1732       retrieve the query object itself this way if needed:
1733
1734           $q = $in{'CGI'};
1735
1736       Either way it allows you to start using the more interesting features
1737       of CGI.pm without rewriting your old scripts from scratch.
1738
1739       Unlike CGI.pm all the cgi-lib.pl functions from Version 2.18 are
1740       supported:
1741
1742           ReadParse()
1743           SplitParam()
1744           MethGet()
1745           MethPost()
1746           MyBaseUrl()
1747           MyURL()
1748           MyFullUrl()
1749           PrintHeader()
1750           HtmlTop()
1751           HtmlBot()
1752           PrintVariables()
1753           PrintEnv()
1754           CgiDie()
1755           CgiError()
1756

COMPATIBILITY WITH CGI.pm

1758       I has long been suggested that the CGI and HTML parts of CGI.pm should
1759       be split into separate modules (even the author suggests this!),
1760       CGI::Simple represents the realization of this and contains the
1761       complete CGI side of CGI.pm. Code-wise it weighs in at a little under
1762       30% of the size of CGI.pm at a little under 1000 lines.
1763
1764       A great deal of care has been taken to ensure that the interface
1765       remains unchanged although a few tweaks have been made. The test suite
1766       is extensive and includes all the CGI.pm test scripts as well as a
1767       series of new test scripts. You may like to have a look at /t/concur.t
1768       which makes 160 tests of CGI::Simple and CGI in parallel and compares
1769       the results to ensure they are identical. This is the case as of CGI.pm
1770       2.78.
1771
1772       You can't make an omelet without breaking eggs. A large number of
1773       methods and global variables have been deleted as detailed below. Some
1774       pragmas are also gone. In the tarball there is a script /misc/check.pl
1775       that will check if a script seems to be using any of these now non
1776       existent methods, globals or pragmas. You call it like this:
1777
1778           perl check.pl <files>
1779
1780       If it finds any likely candidates it will print a line with the line
1781       number, problem method/global and the complete line. For example here
1782       is some output from running the script on CGI.pm:
1783
1784           ...
1785           3162: Problem:'$CGI::OS'   local($CRLF) = "\015\012" if $CGI::OS eq 'VMS';
1786           3165: Problem:'fillBuffer' $self->fillBuffer($FILLUNIT);
1787           ....
1788

DIFFERENCES FROM CGI.pm

1790       CGI::Simple is strict and warnings compliant.
1791
1792       There are 4 modules in this distribution:
1793
1794           CGI/Simple.pm           supplies all the core code.
1795           CGI/Simple/Cookie.pm    supplies the cookie handling functions.
1796           CGI/Simple/Util.pm      supplies a variety of utility functions
1797           CGI/Simple/Standard.pm  supplies a functional interface for Simple.pm
1798
1799       Simple.pm is the core module that provide all the essential
1800       functionality.  Cookie.pm is a shortened rehash of the CGI.pm module of
1801       the same name which supplies the required cookie functionality. Util.pm
1802       has been recoded to use an internal object for data storage and
1803       supplies rarely needed non core functions and/or functions needed for
1804       the HTML side of things. Standard.pm is a wrapper module that supplies
1805       a complete functional interface to the OO back end supplied by
1806       CGI::Simple.
1807
1808       Although a serious attempt has been made to keep the interface
1809       identical, some minor changes and tweaks have been made. They will
1810       likely be insignificant to most users but here are the gory details.
1811
1812   Globals Variables
1813       The list of global variables has been pruned by 75%. Here is the
1814       complete list of the global variables used:
1815
1816           $VERSION = "0.01";
1817           # set this to 1 to use CGI.pm default global settings
1818           $USE_CGI_PM_DEFAULTS = 0 unless defined $USE_CGI_PM_DEFAULTS;
1819           # see if user wants old  CGI.pm defaults
1820           do{ _use_cgi_pm_global_settings(); return } if $USE_CGI_PM_DEFAULTS;
1821           # no file uploads by default, set to 0 to enable uploads
1822           $DISABLE_UPLOADS = 1 unless defined $DISABLE_UPLOADS;
1823           # use a post max of 100K, set to -1 for no limits
1824           $POST_MAX = 102_400 unless defined $POST_MAX;
1825           # do not include undefined params parsed from query string
1826           $NO_UNDEF_PARAMS = 0 unless defined $NO_UNDEF_PARAMS;
1827           # separate the name=value pairs with ; rather than &
1828           $USE_PARAM_SEMICOLONS = 0 unless defined $USE_PARAM_SEMICOLONS;
1829           # only print headers once
1830           $HEADERS_ONCE = 0 unless defined $HEADERS_ONCE;
1831           # Set this to 1 to enable NPH scripts
1832           $NPH = 0 unless defined $NPH;
1833           # 0 => no debug, 1 => from @ARGV,  2 => from STDIN
1834           $DEBUG = 0 unless defined $DEBUG;
1835           # filter out null bytes in param - value pairs
1836           $NO_NULL  = 1 unless defined $NO_NULL;
1837           # set behavior when cgi_err() called -1 => silent, 0 => carp, 1 => croak
1838           $FATAL = -1 unless defined $FATAL;
1839
1840       Four of the default values of the old CGI.pm variables have been
1841       changed.  Unlike CGI.pm which by default allows unlimited POST data and
1842       file uploads by default CGI::Simple limits POST data size to 100kB and
1843       denies file uploads by default. $USE_PARAM_SEMICOLONS is set to 0 by
1844       default so we use (old style) & rather than ; as the pair separator for
1845       query strings. Debugging is disabled by default.
1846
1847       There are three new global variables. If $NO_NULL is true (the default)
1848       then CGI::Simple will strip null bytes out of names, values and
1849       keywords. Null bytes can do interesting things to C based code like
1850       Perl. Uploaded files are not touched. $FATAL controls the behavior when
1851       cgi_error() is called.  The default value of -1 makes errors silent.
1852       $USE_CGI_PM_DEFAULTS reverts the defaults to the CGI.pm standard values
1853       ie unlimited file uploads via POST for DNS attacks. You can also get
1854       the defaults back by using the '-default' pragma in the use:
1855
1856           use CGI::Simple qw(-default);
1857           use CGI::Simple::Standard qw(-default);
1858
1859       The values of the global variables are stored in the CGI::Simple object
1860       and can be referenced and changed using the globals() method like this:
1861
1862           my $value = $q->globals( 'VARNAME' );      # get
1863           $q->globals( 'VARNAME', 'some value' );    # set
1864
1865       As with many CGI.pm methods if you pass the optional value that will be
1866       set.
1867
1868       The $CGI::Simple::VARNAME = 'N' syntax is only useful prior to calling
1869       the new() constructor. After that all reference is to the values stored
1870       in the CGI::Simple object so you must change these using the globals()
1871       method.
1872
1873       $DISABLE_UPLOADS and $POST_MAX *must* be set prior to calling the
1874       constructor if you want the changes to have any effect as they control
1875       behavior during initialization. This is the same a CGI.pm although some
1876       people seem to miss this rather important point and set these after
1877       calling the constructor which does nothing.
1878
1879       The following globals are no longer relevant and have all been deleted:
1880
1881           $AUTOLOADED_ROUTINES
1882           $AUTOLOAD_DEBUG
1883           $BEEN_THERE
1884           $CRLF
1885           $DEFAULT_DTD
1886           $EBCDIC
1887           $FH
1888           $FILLUNIT
1889           $IIS
1890           $IN
1891           $INITIAL_FILLUNIT
1892           $JSCRIPT
1893           $MAC
1894           $MAXTRIES
1895           $MOD_PERL
1896           $NOSTICKY
1897           $OS
1898           $PERLEX
1899           $PRIVATE_TEMPFILES
1900           $Q
1901           $QUERY_CHARSET
1902           $QUERY_PARAM
1903           $SCRATCH
1904           $SL
1905           $SPIN_LOOP_MAX
1906           $TIMEOUT
1907           $TMPDIRECTORY
1908           $XHTML
1909           %EXPORT
1910           %EXPORT_OK
1911           %EXPORT_TAGS
1912           %OVERLOAD
1913           %QUERY_FIELDNAMES
1914           %SUBS
1915           @QUERY_PARAM
1916           @TEMP
1917
1918       Notes: CGI::Simple uses IO::File->new_tmpfile to get tempfile
1919       filehandles.  These are private by default so $PRIVATE_TEMPFILES is no
1920       longer required nor is $TMPDIRECTORY. The value that were stored in
1921       $OS, $CRLF, $QUERY_CHARSET and $EBCDIC are now stored in the
1922       CGI::Simple::Util object where they find most of their use. The
1923       $MOD_PERL and $PERLEX values are now stored in our CGI::Simple object.
1924       $IIS was only used once in path_info().  $SL the system specific / \ :
1925       path delimiter is not required as we let IO::File handle our tempfile
1926       requirements. The rest of the globals are HTML related, export related,
1927       hand rolled autoload related or serve obscure purposes in CGI.pm
1928
1929   Changes to pragmas
1930       There are some new pragmas available. See the pragmas section for
1931       details.  The following CGI.pm pragmas are not available:
1932
1933           -any
1934           -compile
1935           -nosticky
1936           -no_xhtml
1937           -private_tempfiles
1938
1939   Filehandles
1940       Unlike CGI.pm which tries to accept all filehandle like objects only
1941       \*FH and $fh are accepted by CGI::Simple as file accessors for new()
1942       and save().  IO::File objects work fine.
1943
1944   Hash interface
1945           %hash = $q->Vars();     # pack values with "\0";
1946           %hash = $q->Vars(",");  # comma separate values
1947
1948       You may optionally pass Vars() a string that will be used to separate
1949       multiple values when they are packed into the single hash value. If no
1950       value is supplied the default "\0" (null byte) will be used. Null bytes
1951       are dangerous things for C based code (ie Perl).
1952
1953   cgi-lib.pl
1954       All the cgi-lib.pl 2.18 routines are supported. Unlike CGI.pm all the
1955       subroutines from cgi-lib.pl are included. They have been GOLFED down to
1956       25 lines but they all work pretty much the same as the originals.
1957

CGI::Simple COMPLETE METHOD LIST

1959       Here is a complete list of all the CGI::Simple methods.
1960
1961   Guts (hands off, except of course for new)
1962           _initialize_globals
1963           _use_cgi_pm_global_settings
1964           _store_globals
1965           import
1966           _reset_globals
1967           new
1968           _initialize
1969           _read_parse
1970           _parse_params
1971           _add_param
1972           _parse_keywordlist
1973           _parse_multipart
1974           _save_tmpfile
1975           _read_data
1976
1977   Core Methods
1978           param
1979           add_param
1980           param_fetch
1981           url_param
1982           keywords
1983           Vars
1984           append
1985           delete
1986           Delete
1987           delete_all
1988           Delete_all
1989           upload
1990           upload_info
1991           query_string
1992           parse_query_string
1993           parse_keywordlist
1994
1995   Save and Restore from File Methods
1996           _init_from_file
1997           save
1998           save_parameters
1999
2000   Miscellaneous Methods
2001           url_decode
2002           url_encode
2003           escapeHTML
2004           unescapeHTML
2005           put
2006           print
2007
2008   Cookie Methods
2009           cookie
2010           raw_cookie
2011
2012   Header Methods
2013           header
2014           cache
2015           no_cache
2016           redirect
2017
2018   Server Push Methods
2019           multipart_init
2020           multipart_start
2021           multipart_end
2022           multipart_final
2023
2024   Debugging Methods
2025           read_from_cmdline
2026           Dump
2027           as_string
2028           cgi_error
2029
2030   cgi-lib.pl Compatibility Routines - all 2.18 functions available
2031           _shift_if_ref
2032           ReadParse
2033           SplitParam
2034           MethGet
2035           MethPost
2036           MyBaseUrl
2037           MyURL
2038           MyFullUrl
2039           PrintHeader
2040           HtmlTop
2041           HtmlBot
2042           PrintVariables
2043           PrintEnv
2044           CgiDie
2045           CgiError
2046
2047   Accessor Methods
2048           version
2049           nph
2050           all_parameters
2051           charset
2052           crlf                # new, returns OS specific CRLF sequence
2053           globals             # get/set global variables
2054           auth_type
2055           content_length
2056           content_type
2057           document_root
2058           gateway_interface
2059           path_translated
2060           referer
2061           remote_addr
2062           remote_host
2063           remote_ident
2064           remote_user
2065           request_method
2066           script_name
2067           server_name
2068           server_port
2069           server_protocol
2070           server_software
2071           user_name
2072           user_agent
2073           virtual_host
2074           path_info
2075           Accept
2076           accept
2077           http
2078           https
2079           protocol
2080           url
2081           self_url
2082           state
2083

NEW METHODS IN CGI::Simple

2085       There are a few new methods in CGI::Simple as listed below. The
2086       highlights are the parse_query_string() method to add the QUERY_STRING
2087       data to your object if the method was POST. The no_cache() method adds
2088       an expires now directive and the Pragma: no-cache directive to the
2089       header to encourage some browsers to do the right thing. PrintEnv()
2090       from the cgi-lib.pl routines will dump an HTML friendly list of the
2091       %ENV and makes a handy addition to Dump() for use in debugging. The
2092       upload method now accepts a filepath as an optional second argument as
2093       shown in the synopsis. If this is supplied the uploaded file will be
2094       written to there automagically.
2095
2096   Internal Routines
2097           _initialize_globals()
2098           _use_cgi_pm_global_settings()
2099           _store_globals()
2100           _initialize()
2101           _init_from_file()
2102           _read_parse()
2103           _parse_params()
2104           _add_param()
2105           _parse_keywordlist()
2106           _parse_multipart()
2107           _save_tmpfile()
2108           _read_data()
2109
2110   New Public Methods
2111           add_param()             # adds a param/value(s) pair +/- overwrite
2112           upload_info()           # uploaded files MIME type and size
2113           url_decode()            # decode s url encoded string
2114           url_encode()            # url encode a string
2115           parse_query_string()    # add QUERY_STRING data to $q object if 'POST'
2116           no_cache()              # add both the Pragma: no-cache
2117                                   # and Expires/Date => 'now' to header
2118
2119   cgi-lib.pl methods added for completeness
2120           _shift_if_ref()         # internal hack reminiscent of self_or_default :-)
2121           MyBaseUrl()
2122           MyURL()
2123           MyFullUrl()
2124           PrintVariables()
2125           PrintEnv()
2126           CgiDie()
2127           CgiError()
2128
2129   New Accessors
2130           crlf()                  # returns CRLF sequence
2131           globals()               # global vars now stored in $q object - get/set
2132           content_length()        # returns $ENV{'CONTENT_LENGTH'}
2133           document_root()         # returns $ENV{'DOCUMENT_ROOT'}
2134           gateway_interface()     # returns $ENV{'GATEWAY_INTERFACE'}
2135

METHODS IN CGI.pm NOT IN CGI::Simple

2137       Here is a complete list of what is not included in CGI::Simple.
2138       Basically all the HTML related stuff plus large redundant chunks of the
2139       guts. The check.pl script in the /misc dir will check to see if a
2140       script is using any of these.
2141
2142   Guts - rearranged, recoded, renamed and hacked out of existence
2143           initialize_globals()
2144           compile()
2145           expand_tags()
2146           self_or_default()
2147           self_or_CGI()
2148           init()
2149           to_filehandle()
2150           save_request()
2151           parse_params()
2152           add_parameter()
2153           binmode()
2154           _make_tag_func()
2155           AUTOLOAD()
2156           _compile()
2157           _setup_symbols()
2158           new_MultipartBuffer()
2159           read_from_client()
2160           import_names()     # I dislike this and left it out, so shoot me.
2161
2162   HTML Related
2163           autoEscape()
2164           URL_ENCODED()
2165           MULTIPART()
2166           SERVER_PUSH()
2167           start_html()
2168           _style()
2169           _script()
2170           end_html()
2171           isindex()
2172           startform()
2173           start_form()
2174           end_multipart_form()
2175           start_multipart_form()
2176           endform()
2177           end_form()
2178           _textfield()
2179           textfield()
2180           filefield()
2181           password_field()
2182           textarea()
2183           button()
2184           submit()
2185           reset()
2186           defaults()
2187           comment()
2188           checkbox()
2189           checkbox_group()
2190           _tableize()
2191           radio_group()
2192           popup_menu()
2193           scrolling_list()
2194           hidden()
2195           image_button()
2196           nosticky()
2197           default_dtd()
2198
2199   Upload Related
2200       CGI::Simple uses anonymous tempfiles supplied by IO::File to spool
2201       uploaded files to.
2202
2203           private_tempfiles() # automatic in CGI::Simple
2204           tmpFileName()       # all upload files are anonymous
2205           uploadInfo()        # relied on FH access, replaced with upload_info()
2206
2207   Really Private Subs (marked as so)
2208           previous_or_default()
2209           register_parameter()
2210           get_fields()
2211           _set_values_and_labels()
2212           _compile_all()
2213           asString()
2214           compare()
2215
2216   Internal Multipart Parsing Routines
2217           read_multipart()
2218           readHeader()
2219           readBody()
2220           read()
2221           fillBuffer()
2222           eof()
2223

EXPORT

2225       Nothing.
2226

AUTHOR INFORMATION

2228       Originally copyright 2001 Dr James Freeman <jfreeman@tassie.net.au>
2229       This release by Andy Armstrong <andy@hexten.net>
2230
2231       This package is free software and is provided "as is" without express
2232       or implied warranty. It may be used, redistributed and/or modified
2233       under the terms of the Perl Artistic License (see
2234       http://www.perl.com/perl/misc/Artistic.html)
2235
2236       Address bug reports and comments to: andy@hexten.net.  When sending bug
2237       reports, please provide the version of CGI::Simple, the version of
2238       Perl, the name and version of your Web server, and the name and version
2239       of the operating system you are using.  If the problem is even remotely
2240       browser dependent, please provide information about the affected
2241       browsers as well.
2242
2243       Address bug reports and comments to: andy@hexten.net
2244

CREDITS

2246       Lincoln D. Stein (lstein@cshl.org) and everyone else who worked on the
2247       original CGI.pm upon which this module is heavily based
2248
2249       Brandon Black for some heavy duty testing and bug fixes
2250
2251       John D Robinson and Jeroen Latour for helping solve some interesting
2252       test failures as well as Perlmonks: tommyw, grinder, Jaap, vek, erasei,
2253       jlongino and strider_corinth
2254
2255       Thanks for patches to:
2256
2257       Ewan Edwards, Joshua N Pritikin, Mike Barry, Michael Nachbaur, Chris
2258       Williams, Mark Stosberg, Krasimir Berov, Yamada Masahiro
2259
2261       Copyright (c) 2007, Andy Armstrong "<andy@hexten.net>". All rights
2262       reserved.
2263
2264       This module is free software; you can redistribute it and/or modify it
2265       under the same terms as Perl itself. See perlartistic.
2266

SEE ALSO

2268       CGI, CGI::Simple::Standard, CGI::Simple::Cookie, CGI::Simple::Util,
2269       CGI::Minimal
2270
2271
2272
2273perl v5.12.2                      2011-01-21                    CGI::Simple(3)
Impressum