home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / asp-perl.bat < prev    next >
Encoding:
DOS Batch File  |  2003-09-17  |  4.3 KB  |  169 lines

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S %0 %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
  11. goto endofperl
  12. @rem ';
  13. #!/usr/bin/perl
  14. #line 15
  15.  
  16. # for more accurate per request time accounting
  17. BEGIN {
  18.     eval "use Time::HiRes";
  19.     $Apache::ASP::QuickStartTime = eval { &Time::HiRes::time(); } || time();
  20. }
  21.  
  22. # help section
  23. use File::Basename;
  24. use Getopt::Std;
  25. use Cwd;
  26. use Carp qw(confess);
  27. use Apache::ASP::CGI;
  28.  
  29.  
  30. =head1 NAME
  31.  
  32. asp-perl - Apache::ASP CGI and command line script processor
  33.  
  34. =head1 SYNOPSIS
  35.  
  36. asp-perl [-hsdb] [-f asp.conf] [-o directory] file1 @arguments file2 @arguments ...
  37.  
  38.     -h  Help you are getting now!
  39.     -f  Specify an alternate configuration file other than ./asp.conf
  40.     -s  Setup $Session and $Application state for script.
  41.     -d  Set to debug code upon errors.
  42.     -b  Only return body of document, no headers.
  43.     -o  Output directory, writes to files there instead of STDOUT
  44.     -p  GlobalPackage config, what perl package are the scripts compiled in.
  45.  
  46. =head1 DESCRIPTION
  47.  
  48. This program will run Apache::ASP scripts from the command line.
  49. Each file that is specified will be run, and the
  50. $Request->QueryString() and $Request->Form() data will be
  51. initialized by the @arguments following the script file name.
  52.  
  53. The @arguments will be written as space separated
  54. words, and will be initialized as an associate array where
  55. %arguments = @arguments.  As an example:
  56.  
  57.  asp file.asp key1 value1 key2 value2
  58.  
  59. would be similar to calling the file.asp in a web environment like
  60.  
  61.  /file.asp?key1=value1&key2=value2
  62.  
  63. The asp.conf script will be read from the current directory
  64. for parameters that would be set with PerlSetVar normally under
  65. mod_perl.  For more information on how to configure the asp.conf
  66. file, please see < http://www.apache-asp.org/cgi.html >
  67.  
  68. =head1 SEE ALSO
  69.  
  70. perldoc Apache::ASP, and also http://www.apache-asp.org
  71.  
  72. =head1 COPYRIGHT
  73.  
  74. Copyright 1998-2002 Joshua Chamas, Chamas Enterprises Inc.
  75.  
  76. This program is distributed under the GPL.  Please see the LICENSE
  77. file in the Apache::ASP distribution for more information.
  78.  
  79. =cut
  80.  
  81. $SIG{__DIE__} = \&confess;
  82. getopts('hsdbo:p:f:');
  83.  
  84. if($opt_h || ! @ARGV) {
  85.     open(SCRIPT, $0) || die("can't open $0 for reading: $!");
  86.     my $script = join('', <SCRIPT>);
  87.     close SCRIPT;
  88.     $script =~ /=pod\s(.*?)=cut/s;
  89.     my $pod = $1;
  90.     $pod =~ s/\=head1 (\w+)/$1/isg;
  91.     $pod =~ s/DESCRIPTION.*//isg;
  92.     print $pod;
  93.     print "\"perldoc asp-perl\" or \"man asp-perl\" for more information\n\n";
  94.  
  95.     exit;
  96. }
  97.  
  98. if($opt_o && ! -e $opt_o) {
  99.     mkdir($opt_o, 0750) || die("can't mkdir $opt_o");    
  100. }
  101.  
  102. $Config = '';
  103. my $config_file = $opt_f || 'asp.conf';
  104. if(-e $config_file) {
  105.     # read in .asp to load %Config
  106.     open(CONFIG, $config_file) || die("can't open $config_file: $!");
  107.     $Config = join('', <CONFIG>);
  108.     close CONFIG;
  109. } else {
  110.     if($opt_f) {
  111.     die("Configuration file $opt_f does not exist!");
  112.     }
  113. }
  114.  
  115. my $cwd = cwd();
  116. while(@ARGV) {
  117.     $cwd && (chdir($cwd) || die("can't chdir to $cwd"));
  118.     my $file = shift @ARGV;
  119.     my @script_args;
  120.  
  121.     unless(-e $file) {
  122.     print "file $file does not exist\n";
  123.     next;
  124.     }
  125.  
  126.     while(@ARGV) {
  127.     last if(-e $ARGV[0]);
  128.     push(@script_args, shift @ARGV);
  129.     }
  130.     
  131.     if($opt_o) {
  132.     my $basename = basename($file);
  133.     open(STDOUT, ">$opt_o/$basename") || die("can't open $opt_o/$basename for writing");
  134.     }
  135.  
  136.     $r = Apache::ASP::CGI->init($file, @script_args);
  137.     $0 = $file; # might need real $0 in $Config
  138.     eval $Config;
  139.     $@ && die("can't eval config error: $@");
  140.  
  141.     $r->dir_config->set('NoState', 0) if $opt_s;
  142.     if($opt_d) {
  143.     $r->dir_config->set('Debug', -3);
  144.     $r->dir_config->set('CommandLine', 1);
  145.     }
  146.     if($opt_b) {
  147.     $r->dir_config->set('NoHeaders', 1);
  148.     }
  149.     if($opt_p) {
  150.     $r->dir_config->set('GlobalPackage', $opt_p);
  151.     }
  152.  
  153.     for(keys %Config) {
  154.     $r->dir_config->set($_, $Config{$_});
  155.     }
  156.  
  157.     &Apache::ASP::handler($r);
  158.  
  159.     if($opt_o) {
  160.     close STDOUT;
  161.     }
  162.     
  163. }
  164.  
  165.  
  166.  
  167. __END__
  168. :endofperl
  169.