Leo Charre > CGI-Scriptpaths > CGI::Scriptpaths

Download:
CGI-Scriptpaths-1.03.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 1.03   Source  

NAME ^

CGI::Scriptpaths - find web relevant paths even without ENV set

SYNOPSIS ^

   use CGI::Scriptpaths ':all';

   $CGI::Scriptpaths::DEBUG = 1;

   my $abs_path            = script_abs_path();
   my $abs_loc             = script_abs_loc();
   my $filename            = script_filename();
   my $filename_only       = script_filename_only();
   my $script_extension    = script_ext();
   my $form_action         = script_rel_path();
   my $script_dir          = script_rel_loc();
   my $docroot             = DOCUMENT_ROOT();
   my $cgibin              = abs_cgibin(;)

DESCRIPTION ^

Sometimes you need to find where the document root is, and maybe DOCUMENT ROOT is not set Sometimes you want to get some info about the script, like it's abs path, it's rel path so a form knows how to point to itself.

This uses some tricks to find those things even if environment variables are not set.

WHY

Even outside a cgi environment, a script usinng this can find its way around. For example in this fs hierarchy:

   /home/user/
   /home/user/public_html
   /home/user/cgi-bin
   /home/user/cgi-bin/a/script.cgi

Even without DOCUMENT_ROOT set, script.cgi knows that document root is /home/user/public_html. Valid dir names are also htdocs and html. So, in this following fs hierarchy, it will also know to find document root:

   /home/user/
   /home/user/html
   /home/user/html/script.cgi   
   /home/user/cgi-bin

The way it works, is it steps backwards and looks for these directories.

SUBS ^

None of these are exported by default.

script_abs_path()

returns script's absolute location on failure warns and returns undef

script_abs_loc()

returns script's abs path to the directory it resides in on failure warns and returns undef

script_filename()

returns the script's filename

script_filename_only()

returns the script's filename without ext (if there was one)

script_ext()

returns script's ext (without dot) if there is one returns undef if none

abs_cgibin()

tries to find path to cgi-bin may warn and return undef

DOCUMENT_ROOT()

assumes this is a website and returns document root if $ENV{DOCUMENT_ROOT} is not set, it tries to test and guess for it on failure returns undef

script_rel_path()

returns script's relative path to DOCUMENT_ROOT() warns and returns undef on failure

script_rel_loc()

returns the path of the directory the script resides in, relative to DOCUMENT_ROOT() warns and returns undef on failure

script_is_in_DOCUMENT_ROOT()

returns boolean returns undef if DOCUMENT_ROOT() can't return value.

script_is_in_cgibin()

returns boolean returns undef if abs_cgibin() can't return value.

DEBUG ^

   $CGI::Scriptpaths::DEBUG  = 1;

BUGS ^

Please contact AUTHOR.

AUTHOR ^

Leo Charre leocharre at cpan dot org

SEE ALSO ^

Cwd::Ext Cwd

syntax highlighting: