CGI-Info

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

#### OUTPUT

    { type => 'object', isa => 'CGI::Info' }

### MESSAGES

- `use ->new() not ::new() to instantiate`

    **Level**: fatal (croak).
    **Cause**: called as `CGI::Info::new()` (double-colon) instead of `CGI::Info->new()`.
    **Action**: change the call-site to use the arrow notation.

- `Logger must be an object with info() and error() methods`

    **Level**: fatal (croak).
    **Cause**: the `logger` argument is not a blessed object, or does not
    implement `info()`, `warn()`, and `error()` methods.
    **Action**: pass a compliant logger such as a [Log::Abstraction](https://metacpan.org/pod/Log%3A%3AAbstraction)-based object.

- `expect has been deprecated, use allow instead`

    **Level**: fatal (croak).
    **Cause**: the removed `expect` parameter was passed to `new()`.
    **Action**: replace `expect => [...]` with `allow => { key => qr/.../ }`.

## script\_name

Retrieves the name of the executing CGI script.
This is useful for POSTing,
thus avoiding hard-coded paths into forms.

        use CGI::Info;

        my $info = CGI::Info->new();
        my $script_name = $info->script_name();
        # ...
        print "<form method=\"POST\" action=$script_name name=\"my_form\">\n";

### API SPECIFICATION

#### INPUT

None.

#### OUTPUT

    {
      type => 'string',
      'min' => 1,
      'nomatch' => qr/^[\/\\]/    # Does not return absolute path
    }

## script\_path

Finds the full path name of the script.

        use CGI::Info;

        my $info = CGI::Info->new();
        my $fullname = $info->script_path();
        my @statb = stat($fullname);

        if(@statb) {
                my $mtime = localtime $statb[9];
                print "Last-Modified: $mtime\n";
                # TODO: only for HTTP/1.1 connections
                # $etag = Digest::MD5::md5_hex($html);
                printf "ETag: \"%x\"\n", $statb[9];
        }

## script\_dir

Returns the file system directory containing the script.

        use CGI::Info;
        use File::Spec;

        my $info = CGI::Info->new();

        print 'HTML files are normally stored in ', $info->script_dir(), '/', File::Spec->updir(), "\n";

        # or
        use lib CGI::Info::script_dir() . '../lib';

## host\_name

Return the host-name of the current web server, according to CGI.
If the name can't be determined from the web server, the system's host-name
is used as a fall back.
This may not be the same as the machine that the CGI script is running on,
some ISPs and other sites run scripts on different machines from those
delivering static content.
There is a good chance that this will be domain\_name() prepended with either
'www' or 'cgi'.

        use CGI::Info;

        my $info = CGI::Info->new();
        my $host_name = $info->host_name();
        my $protocol = $info->protocol();
        # ...
        print "Thank you for visiting our <A HREF=\"$protocol://$host_name\">Website!</A>";

## domain\_name

Domain\_name is the name of the controlling domain for this website.
Usually it will be similar to host\_name, but will lack the http:// or www prefixes.

Can be called as a class method.

## cgi\_host\_url

Return the URL of the machine running the CGI script.

## params

Returns a reference to a hash list of the CGI arguments.

CGI::Info helps you to test your script before deployment on a website:
if it is not in a CGI environment (e.g., the script is being tested from the
command line), the program's command line arguments (a list of key=value pairs)



( run in 0.644 second using v1.01-cache-2.11-cpan-14f38c9f855 )