CGI::Scriptpaths - find web relevant paths even without ENV set
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(;)
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.
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.
None of these are exported by default.
returns script's absolute location on failure warns and returns undef
returns script's abs path to the directory it resides in on failure warns and returns undef
returns the script's filename
returns the script's filename without ext (if there was one)
returns script's ext (without dot) if there is one returns undef if none
tries to find path to cgi-bin may warn and return undef
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
returns script's relative path to DOCUMENT_ROOT() warns and returns undef on failure
returns the path of the directory the script resides in, relative to DOCUMENT_ROOT() warns and returns undef on failure
returns boolean returns undef if DOCUMENT_ROOT() can't return value.
returns boolean returns undef if abs_cgibin() can't return value.
$CGI::Scriptpaths::DEBUG = 1;
Please contact AUTHOR.
Leo Charre leocharre at cpan dot org
Cwd::Ext Cwd
To install CGI::Scriptpaths, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CGI::Scriptpaths
CPAN shell
perl -MCPAN -e shell install CGI::Scriptpaths
For more information on module installation, please visit the detailed CPAN module installation guide.