File: asp-perl

package info (click to toggle)
libapache-asp-perl 2.63-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,120 kB
  • sloc: perl: 6,044; php: 409; sh: 62; lisp: 22; makefile: 10
file content (153 lines) | stat: -rwxr-xr-x 3,824 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/perl

# for more accurate per request time accounting
BEGIN {
    eval "use Time::HiRes";
    $Apache::ASP::QuickStartTime = eval { &Time::HiRes::time(); } || time();
}

# help section
use File::Basename;
use Getopt::Std;
use Cwd;
use Carp qw(confess);
use Apache::ASP::CGI;

=pod

=head1 NAME

asp-perl - Apache::ASP CGI and command line script processor

=head1 SYNOPSIS

asp-perl [-hsdb] [-f asp.conf] [-o directory] file1 @arguments file2 @arguments ...

    -h  Help you are getting now!
    -f  Specify an alternate configuration file other than ./asp.conf
    -s  Setup $Session and $Application state for script.
    -d  Set to debug code upon errors.
    -b  Only return body of document, no headers.
    -o  Output directory, writes to files there instead of STDOUT
    -p  GlobalPackage config, what perl package are the scripts compiled in.

=head1 DESCRIPTION

This program will run Apache::ASP scripts from the command line.
Each file that is specified will be run, and the 
$Request->QueryString() and $Request->Form() data will be 
initialized by the @arguments following the script file name.  

The @arguments will be written as space separated 
words, and will be initialized as an associate array where
%arguments = @arguments.  As an example:

 asp-perl file.asp key1 value1 key2 value2

would be similar to calling the file.asp in a web environment like

 /file.asp?key1=value1&key2=value2

The asp.conf script will be read from the current directory
for parameters that would be set with PerlSetVar normally under
mod_perl.  For more information on how to configure the asp.conf
file, please see < http://www.apache-asp.org/cgi.html > 

=head1 SEE ALSO

perldoc Apache::ASP, and also http://www.apache-asp.org

=head1 COPYRIGHT

Copyright 1998-2004 Joshua Chamas, Chamas Enterprises Inc.

This program is distributed under the GPL.  Please see the LICENSE
file in the Apache::ASP distribution for more information.

=cut

$SIG{__DIE__} = \&confess;
getopts('hsdbo:p:f:');

if($opt_h || ! @ARGV) {
    open(SCRIPT, $0) || die("can't open $0 for reading: $!");
    my $script = join('', <SCRIPT>);
    close SCRIPT;
    $script =~ /=pod\s(.*?)=cut/s;
    my $pod = $1;
    $pod =~ s/\=head1 (\w+)/$1/isg;
    $pod =~ s/DESCRIPTION.*//isg;
    print $pod;
    print "\"perldoc asp-perl\" or \"man asp-perl\" for more information\n\n";

    exit;
}

if($opt_o && ! -e $opt_o) {
    mkdir($opt_o, 0750) || die("can't mkdir $opt_o");    
}

$Config = '';
my $config_file = $opt_f || 'asp.conf';
if(-e $config_file) {
    # read in .asp to load %Config
    open(CONFIG, $config_file) || die("can't open $config_file: $!");
    $Config = join('', <CONFIG>);
    close CONFIG;
} else {
    if($opt_f) {
	die("Configuration file $opt_f does not exist!");
    }
}

my $cwd = cwd();
while(@ARGV) {
    $cwd && (chdir($cwd) || die("can't chdir to $cwd"));
    my $file = shift @ARGV;
    my @script_args;

    unless(-e $file) {
	print "file $file does not exist\n";
	next;
    }

    while(@ARGV) {
	last if(-e $ARGV[0]);
	push(@script_args, shift @ARGV);
    }
	
    if($opt_o) {
	my $basename = basename($file);
	open(STDOUT, ">$opt_o/$basename") || die("can't open $opt_o/$basename for writing");
    }

    $r = Apache::ASP::CGI->init($file, @script_args);
    $0 = $file; # might need real $0 in $Config
    eval $Config;
    $@ && die("can't eval config error: $@");

    $r->dir_config->set('NoState', 0) if $opt_s;
    if($opt_d) {
	$r->dir_config->set('Debug', -3);
	$r->dir_config->set('CommandLine', 1);
    }
    if($opt_b) {
	$r->dir_config->set('NoHeaders', 1);
    }
    if($opt_p) {
	$r->dir_config->set('GlobalPackage', $opt_p);
    }

    for(keys %Config) {
	$r->dir_config->set($_, $Config{$_});
    }

    &Apache::ASP::handler($r);

    if($opt_o) {
	close STDOUT;
    }
    
}