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

NAME

6       CGI::Simple::Standard - a wrapper module for CGI::Simple that provides
7       a function style interface
8

SYNOPSIS

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

DESCRIPTION

88       This module is a wrapper for the completely object oriented CGI::Simple
89       module and provides a simple functional style interface. It provides
90       two different methods to import function names into your namespace.
91
92       Autoloading
93
94       If you specify the '-autoload' pragma like this:
95
96           use CGI::Simple::Standard qw( -autoload );
97
98       Then it will use AUTOLOAD and a symbol table trick to export only those
99       subs you actually call into your namespace. When you specify the
100       '-autoload' pragma this module exports a single AUTOLOAD subroutine
101       into you namespace. This will clash with any AUTOLOAD sub that exists
102       in the calling namespace so if you are using AUTOLOAD for something
103       else don't use this pragma.
104
105       Anyway, when you call a subroutine that is not defined in your script
106       this AUTOLOAD sub will be called. The first time this happens it will
107       initialize a CGI::Simple object and then apply the requested method (if
108       it exists) to it. A fatal exception will be thrown if you try to use an
109       undefined method (function).
110
111       Specified Export
112
113       Alternatively you can specify the functions you wish to import. You can
114       do this on a per function basis like this:
115
116           use CGI::Simple::Standard qw( param upload query_string Dump );
117
118       or utilize the %EXPORT_TAGS that group functions into related groups.
119       Here are the groupings:
120
121         %EXPORT_TAGS = (
122           ':html'     => [ qw(:misc) ],
123           ':standard' => [ qw(:core :access) ],
124           ':cgi'      => [ qw(:core :access) ],
125           ':all'      => [ qw(:core :misc :cookie :header :push :debug :cgi-lib
126                               :access :internal) ],
127           ':core'     => [ qw(param add_param param_fetch url_param keywords
128                               append Delete delete_all Delete_all upload
129                               query_string parse_query_string  parse_keywordlist
130                               Vars save_parameters restore_parameters) ],
131           ':misc'     => [ qw(url_decode url_encode escapeHTML unescapeHTML put) ],
132           ':cookie'   => [ qw(cookie raw_cookie) ],
133           ':header'   => [ qw(header cache no_cache redirect) ],
134           ':push'     => [ qw(multipart_init multipart_start multipart_end
135                               multipart_final) ],
136           ':debug'    => [ qw(Dump as_string cgi_error _cgi_object) ],
137           ':cgi-lib'  => [ qw(ReadParse SplitParam MethGet MethPost MyBaseUrl MyURL
138                               MyFullUrl PrintHeader HtmlTop HtmlBot PrintVariables
139                               PrintEnv CgiDie CgiError Vars) ],
140           ':ssl'      => [ qw(https) ],
141           ':access'   => [ qw(version nph all_parameters charset crlf globals
142                               auth_type content_length content_type document_root
143                               gateway_interface path_translated referer remote_addr
144                               remote_host remote_ident remote_user request_method
145                               script_name server_name server_port server_protocol
146                               server_software user_name user_agent virtual_host
147                               path_info Accept http https protocol url self_url
148                               state) ],
149           ':internal' => [ qw(_initialize_globals _use_cgi_pm_global_settings
150                               _store_globals _reset_globals) ]
151           );
152
153       The familiar CGI.pm tags are available but do not include the HTML
154       functionality. You specify the import of some function groups like
155       this:
156
157       use CGI::Simple::Standard qw( :core :cookie :header );
158
159       Note that the function groups all start with a : char.
160
161       Mix and Match
162
163       You can use the '-autoload' pragma, specifically named function imports
164       and tag group imports together if you desire.
165

$POST_MAX and $DISABLE_UPLOADS

167       If you wish to set $POST_MAX or $DISABLE_UPLOADS you must do this
168       *after* the use statement and *before* the first function call as shown
169       in the synopsis.
170
171       Unlike CGI.pm uploads are disabled by default and the maximum accept‐
172       able data via post is capped at 102_400kB rather than infinity. This is
173       specifically to avoid denial of service attacks by default. To enable
174       uploads and to allow them to be of infinite size you simply:
175
176           $CGI::Simple::Standard::POST_MAX = -1;         # infinite size upload
177           $CGI::Simple::Standard::$DISABLE_UPLOADS = 0;  # enable uploads
178
179       Alternatively you can specify the CGI.pm default values as shown above
180       by specifying the '-default' pragma in your use statement.
181
182           use CGI::Simple::Standard qw( -default ..... );
183

EXPORT

185       Nothing by default.
186
187       Under the '-autoload' pragma the AUTOLOAD subroutine is exported into
188       the calling namespace. Additional subroutines are only imported into
189       this namespace if you physically call them. They are installed in the
190       symbol table the first time you use them to save repeated calls to
191       AUTOLOAD.
192
193       If you specifically request a function or group of functions via an
194       EXPORT_TAG then stubs of these functions are exported into the calling
195       namespace. These stub functions will be replaced with the real func‐
196       tions only if you actually call them saving wasted compilation effort.
197

FUNCTION DETAILS

199       This is a wrapper module for CGI::Simple. Virtually all the methods
200       available in the OO interface are available via the functional inter‐
201       face. Several method names are aliased to prevent namespace conflicts:
202
203           $q->delete('foo')   =>  Delete('foo')
204           $q->delete_all      =>  Delete_all() or delete_all()
205           $q->save(\*FH)      =>  save_parameters(\*FH)
206           $q->accept()        =>  Accept()
207
208       Although you could use the new() function to genrate new OO CGI::Simple
209       objects the restore_parameters() function is a better choice as it
210       operates like new but on the correct underlying CGI::Simple object for
211       the functional interface.
212
213       restore_parameters() can be used exactly as you might use new() in that
214       you can supply arguments to it such as query strings, hashes and file
215       handles to re-initialize your underlying object.
216
217           $q->new CGI::Simple()                => restore_parameters()
218           $q->new CGI::Simple({foo=>'bar'})    => restore_parameters({foo=>'bar'})
219           $q->new CGI::Simple($query_string)   => restore_parameters($query_string)
220           $q->new CGI::Simple(\*FH)            => restore_parameters(\*FH)
221
222       For full details of the available functions see the CGI::Simple docs.
223       Just remove the $q-> part and use the method name directly.
224

BUGS

226       As this is 0.01 there are almost bound to be some.
227

AUTHOR

229       Dr James Freeman <jfreeman@tassie.net.au>
230
231       This package is free software and is provided "as is" without express
232       or implied warranty. It may be used, redistributed and/or modified
233       under the terms of the Perl Artistic License (see
234       http://www.perl.com/perl/misc/Artistic.html)
235

CREDITS

237       The interface and key sections of the CGI::Simple code come from CGI.pm
238       by Lincoln Stein.
239

SEE ALSO

241       "CGI::Simple which is the back end for this module", CGI.pm by Lincoln
242       Stein
243
244
245
246perl v5.8.8                       2004-11-22               Simple::Standard(3)
Impressum