CGI-Compile

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

METHODS

 new

    Does not need to be called, you only need to call it if you want to set
    your own namespace_root for the generated packages into which the CGIs
    are compiled into.

    Otherwise you can just call "compile" as a class method and the object
    will be instantiated with a namespace_root of CGI::Compile::ROOT.

    You can also set return_exit_val, see "RETURN CODE" for details.

    Example:

        my $compiler = CGI::Compile->new(namespace_root => 'My::CGIs');
        my $cgi      = $compiler->compile('/var/www/cgi-bin/my.cgi');

 compile

    Takes either a path to a perl CGI script or a source code and some
    other optional parameters and wraps it into a coderef for execution.

    Can be called as either a class or instance method, see "new" above.

    Parameters:

      * $cgi_script

      Path to perl CGI script file or a scalar reference that contains the
      source code of CGI script, required.

      * $package

      Optional, package to install the script into, defaults to the path
      parts of the script joined with _, and all special characters
      converted to _%2x, prepended with CGI::Compile::ROOT::.

      E.g.:

          /var/www/cgi-bin/foo.cgi

      becomes:

          CGI::Compile::ROOT::var_www_cgi_2dbin_foo_2ecgi

    Returns:

      * $coderef

      $cgi_script or $$code compiled to coderef.

SCRIPT ENVIRONMENT

 ARGUMENTS

    Things like the query string and form data should generally be in the
    appropriate environment variables that things like CGI expect.

    You can also pass arguments to the generated coderef, they will be
    locally aliased to @_ and @ARGV.

 BEGIN and END blocks

    BEGIN blocks are called once when the script is compiled. END blocks
    are called when the Perl interpreter is unloaded.

    This may cause surprising effects. Suppose, for instance, a script that
    runs in a forking web server and is loaded in the parent process. END
    blocks will be called once for each worker process and another time for
    the parent process while BEGIN blocks are called only by the parent
    process.

 %SIG

    The %SIG hash is preserved meaning the script can change signal
    handlers at will. The next invocation gets a pristine %SIG again.

 exit and exceptions

    Calls to exit are intercepted and converted into exceptions. When the
    script calls exit 19 and exception is thrown and $@ contains a
    reference pointing to the array

        ["EXIT\n", 19]

    Naturally, "$^S" in perlvar (exceptions being caught) is always true
    during script runtime.

    If you really want to exit the process call CORE::exit or set
    $CGI::Compile::USE_REAL_EXIT to true before calling exit:

        $CGI::Compile::USE_REAL_EXIT = 1;
        exit 19;

    Other exceptions are propagated out of the generated coderef. The
    coderef's caller is responsible to catch them or the process will exit.

 Return Code

    The generated coderef's exit value is either the parameter that was
    passed to exit or the value of the last statement of the script. The
    return code is converted into an integer.

    On a 0 exit, the coderef will return 0.

    On an explicit non-zero exit, by default an exception will be thrown of
    the form:

        exited nonzero: <n>

    where n is the exit value.

    This only happens for an actual call to "exit" in perfunc, not if the
    last statement value is non-zero, which will just be returned from the
    coderef.

    If you would prefer that explicit non-zero exit values are returned,
    rather than thrown, pass:

        return_exit_val => 1



( run in 1.758 second using v1.01-cache-2.11-cpan-97f6503c9c8 )