#!/usr/local/bin/perl -Tw

use Apache ();
use strict;
use vars qw($Scalar @Array %Hash); #for testing perl-status

$Scalar = 1;
@Array  = qw(one two three);
%Hash   = qw(one 1 two 2 three 3);

my $r = Apache->request;
$ENV{PATH} = "/bin";

sub first_one {
    print STDERR "first_one called\n";
    return 0;
}
sub Foo::string {
    print STDERR "Foo::string called\n";
    return 0;
}

if(Apache->can_stack_handlers) {
    $r->push_handlers("PerlLogHandler", "Foo::string");

    Apache->push_handlers("PerlLogHandler", \&first_one);

    $r->push_handlers("PerlLogHandler", sub {
	print STDERR "__ANON__ called\n";
	return 0;
    });
}

#$r->warn("sequence number: " . $r->seqno);

$r->content_type("text/html");
$r->send_http_header;

my(@args);

if (@args = $r->args) {
    $r->write_client(
       "ARGS: ",
       join(", ", map { $_ = qq{"$_"} } @args),
       "\n\n");
} else {
    $r->print("No command line arguments passed to script\n\n");
}

my($key,$val);
while (($key,$val) = each %ENV) {
   $r->print("$key=$val\n");
}

if ($ENV{CONTENT_LENGTH}) {
    #$len = $ENV{CONTENT_LENGTH};
    my $content = $r->content;

    eval { system $content };
    die "TaintCheck failed, I can `system \$content'" unless $@;
    warn "TRAPPED: `system \$r->content' '$@'\n";

    $r->print("\nContent\n-------\n$content");
}

