Dmitry Koterov > CGI-WebIn > CGI::WebIn

Download:
CGI-WebIn-2.03.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 2.03   Source  

NAME ^

CGI::WebIn - Perl extension for reading CGI form data

SYNOPSIS ^

  use CGI::WebOut;
  use CGI::WebIn(1);

  # just to avoid "typo warning"
  our ($doGo,%Address,$Count); 

  # count visits
  SetCookie("Count",++$Count,"+10y");

  # is the button pressed?
  if($doGo) {
      print "Hello from $Address{Russia}{Moscow}!";
  }

  print <<EOT;
    You have visited this page $Count times.
    <form action=$SCRIPT_NAME method=post enctype=multipart/form-data>
    <input type=text name="Address{Russia}{Moscow}" value="house">
    <input type=submit name=doGo value="Say hello">
    </form>
  EOT

FEATURES ^

OVERVIEW ^

This module is used to make CGI programmer's work more comfortable. The main idea is to handle input stream (STDIN) and QUERY_STRING environment variable sent by browser and parse their correctly (including multipart forms). Resulting variables are put to %GET, %POST, %COOKIES and %IN (%IN holds ALL the data). Also allows you to get/set cookies (any structure, not only scalars!) with SetCookie() subroutine.

If this module is included without any arguments:

  use CGI::WebIn;

it exports the following: %IN, %GET, %POST, %COOKIES, SetCookie() and DropCookie()

You can specify additional information to be exported by using include arguments:

  use CGI::WebIn 'gpce';

means that all the GET, POST, Cookies and then environment variables will be exported to "usual" package variables. You must not be afraid to write everywhere 'gpce' - the following instruction does the same:

  use CGI::WebIn 'gpce';

DESCRIPTION ^

use CGI::WebIn(1)

Reads all the CGI input and exports it to the caller module (like PHP does).

%IN, %GET, %POST and %COOKIES

%IN contains all the form data. %GET, %POST and %COOKIES holds GET, POST and Cookies variables respectively.

void SetCookie($name, $value [,int $expire][,$path][,$domain][bool $secure])

Sets the cookie in user browser. Value of that cookie is placed to %COOKIES and ALL exported client modules immediately. Format for time $expire can be in any of the forms:

  <stamp> - UNIX timestamp
  0       - one-session cookie
  undef   - drop this cookie
  "now"   - expire immediately
  "+180s" - in 180 seconds
  "+2m"   - in 2 minutes
  "+12h"  - in 12 hours
  "+1d"   - in 1 day
  "+3M"   - in 3 months
  "+2y"   - in 2 years
  "-3m"   - 3 minutes ago(!)
void DropCookie(string $name [,string $path] [,string $domain])

Destroys the specified cookie. Make sure the $path and $domain parameters are the same to previous SetCookie() call.

list of string CGI::WebIn::GetErrors()

While parsing the form input data errors may appear. For example, these QUERY_STRINGs are invalid:

  test[-10]=abc
  test[123456789]=123
  test{1}=a&test[1]=100

Errors may also appear while parsing multipart data. In such cases all the error messages are collected and may be received using this function.

file uploading support

To enable file uploading, you must create the following file .can_upload:

  # directory to upload user files
  dir = .
  # maximum allowed size of the file to upload
  maxsize = 100000

and place it to the current directory. If there is no .can_upload file, uploading is disabled.

AUTHOR ^

Dmitry Koterov <koterov at cpan dot org>, http://www.dklab.ru

SEE ALSO ^

CGI::WebOut.

syntax highlighting: