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 < prev    next >
Encoding:
Text File  |  2003-08-27  |  3.9 KB  |  153 lines

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