home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / asp-perl.bat < prev    next >
Encoding:
DOS Batch File  |  2004-02-08  |  4.3 KB  |  170 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. =pod
  30.  
  31. =head1 NAME
  32.  
  33. asp-perl - Apache::ASP CGI and command line script processor
  34.  
  35. =head1 SYNOPSIS
  36.  
  37. asp-perl [-hsdb] [-f asp.conf] [-o directory] file1 @arguments file2 @arguments ...
  38.  
  39.     -h  Help you are getting now!
  40.     -f  Specify an alternate configuration file other than ./asp.conf
  41.     -s  Setup $Session and $Application state for script.
  42.     -d  Set to debug code upon errors.
  43.     -b  Only return body of document, no headers.
  44.     -o  Output directory, writes to files there instead of STDOUT
  45.     -p  GlobalPackage config, what perl package are the scripts compiled in.
  46.  
  47. =head1 DESCRIPTION
  48.  
  49. This program will run Apache::ASP scripts from the command line.
  50. Each file that is specified will be run, and the 
  51. $Request->QueryString() and $Request->Form() data will be 
  52. initialized by the @arguments following the script file name.  
  53.  
  54. The @arguments will be written as space separated 
  55. words, and will be initialized as an associate array where
  56. %arguments = @arguments.  As an example:
  57.  
  58.  asp-perl file.asp key1 value1 key2 value2
  59.  
  60. would be similar to calling the file.asp in a web environment like
  61.  
  62.  /file.asp?key1=value1&key2=value2
  63.  
  64. The asp.conf script will be read from the current directory
  65. for parameters that would be set with PerlSetVar normally under
  66. mod_perl.  For more information on how to configure the asp.conf
  67. file, please see < http://www.apache-asp.org/cgi.html > 
  68.  
  69. =head1 SEE ALSO
  70.  
  71. perldoc Apache::ASP, and also http://www.apache-asp.org
  72.  
  73. =head1 COPYRIGHT
  74.  
  75. Copyright 1998-2004 Joshua Chamas, Chamas Enterprises Inc.
  76.  
  77. This program is distributed under the GPL.  Please see the LICENSE
  78. file in the Apache::ASP distribution for more information.
  79.  
  80. =cut
  81.  
  82. $SIG{__DIE__} = \&confess;
  83. getopts('hsdbo:p:f:');
  84.  
  85. if($opt_h || ! @ARGV) {
  86.     open(SCRIPT, $0) || die("can't open $0 for reading: $!");
  87.     my $script = join('', <SCRIPT>);
  88.     close SCRIPT;
  89.     $script =~ /=pod\s(.*?)=cut/s;
  90.     my $pod = $1;
  91.     $pod =~ s/\=head1 (\w+)/$1/isg;
  92.     $pod =~ s/DESCRIPTION.*//isg;
  93.     print $pod;
  94.     print "\"perldoc asp-perl\" or \"man asp-perl\" for more information\n\n";
  95.  
  96.     exit;
  97. }
  98.  
  99. if($opt_o && ! -e $opt_o) {
  100.     mkdir($opt_o, 0750) || die("can't mkdir $opt_o");    
  101. }
  102.  
  103. $Config = '';
  104. my $config_file = $opt_f || 'asp.conf';
  105. if(-e $config_file) {
  106.     # read in .asp to load %Config
  107.     open(CONFIG, $config_file) || die("can't open $config_file: $!");
  108.     $Config = join('', <CONFIG>);
  109.     close CONFIG;
  110. } else {
  111.     if($opt_f) {
  112.     die("Configuration file $opt_f does not exist!");
  113.     }
  114. }
  115.  
  116. my $cwd = cwd();
  117. while(@ARGV) {
  118.     $cwd && (chdir($cwd) || die("can't chdir to $cwd"));
  119.     my $file = shift @ARGV;
  120.     my @script_args;
  121.  
  122.     unless(-e $file) {
  123.     print "file $file does not exist\n";
  124.     next;
  125.     }
  126.  
  127.     while(@ARGV) {
  128.     last if(-e $ARGV[0]);
  129.     push(@script_args, shift @ARGV);
  130.     }
  131.     
  132.     if($opt_o) {
  133.     my $basename = basename($file);
  134.     open(STDOUT, ">$opt_o/$basename") || die("can't open $opt_o/$basename for writing");
  135.     }
  136.  
  137.     $r = Apache::ASP::CGI->init($file, @script_args);
  138.     $0 = $file; # might need real $0 in $Config
  139.     eval $Config;
  140.     $@ && die("can't eval config error: $@");
  141.  
  142.     $r->dir_config->set('NoState', 0) if $opt_s;
  143.     if($opt_d) {
  144.     $r->dir_config->set('Debug', -3);
  145.     $r->dir_config->set('CommandLine', 1);
  146.     }
  147.     if($opt_b) {
  148.     $r->dir_config->set('NoHeaders', 1);
  149.     }
  150.     if($opt_p) {
  151.     $r->dir_config->set('GlobalPackage', $opt_p);
  152.     }
  153.  
  154.     for(keys %Config) {
  155.     $r->dir_config->set($_, $Config{$_});
  156.     }
  157.  
  158.     &Apache::ASP::handler($r);
  159.  
  160.     if($opt_o) {
  161.     close STDOUT;
  162.     }
  163.     
  164. }
  165.  
  166.  
  167.  
  168. __END__
  169. :endofperl
  170.