<commit_before>package TestApache::cgihandler;

use strict;
use warnings FATAL => 'all';

use Apache::RequestRec ();
use APR::Table ();

use Apache::Const -compile => qw(OK M_POST);

#test the 1.x style perl-script handler

sub handler {
    my $r = shift;

    $ENV{FOO} = 2;

    if ($r->method_number == Apache::M_POST) {
        my $cl = $r->headers_in->get('content-length');
        my $buff;
#XXX: working around a bug in ithreads Perl
#that would cause modules/cgi #3 to fail
#        read STDIN, $buff, $cl;
        read 'STDIN', $buff, $cl;
        print $buff;
    }
    else {
        print "1..3\n";
        print "ok 1\n", "ok ", "$ENV{FOO}\n";
#XXX: current implementation of tie %ENV to $r->subprocess_env
#     is not threadsafe
#        my $foo = $r->subprocess_env->get('FOO');
        my $foo = $ENV{FOO};
        $foo++;
        print "ok $foo\n";
    }

    Apache::OK;
}

1;
__END__
<NoAutoConfig>
<Location /TestApache__cgihandler>
    <IfDefine PERL_USEITHREADS>
        PerlInterpScope handler
    </Ifdefine>
    SetHandler perl-script
    PerlResponseHandler TestApache::cgihandler
</Location>
</NoAutoConfig>
<commit_msg>remove PerlInterpScope handler for now, as it seems to wreak havoc (which  I can't reproduce). but it doesn't affect the test.<commit_after>package TestApache::cgihandler;

use strict;
use warnings FATAL => 'all';

use Apache::RequestRec ();
use APR::Table ();

use Apache::Const -compile => qw(OK M_POST);

#test the 1.x style perl-script handler

sub handler {
    my $r = shift;

    $ENV{FOO} = 2;

    if ($r->method_number == Apache::M_POST) {
        my $cl = $r->headers_in->get('content-length');
        my $buff;
#XXX: working around a bug in ithreads Perl
#that would cause modules/cgi #3 to fail
#        read STDIN, $buff, $cl;
        read 'STDIN', $buff, $cl;
        print $buff;
    }
    else {
        print "1..3\n";
        print "ok 1\n", "ok ", "$ENV{FOO}\n";
#XXX: current implementation of tie %ENV to $r->subprocess_env
#     is not threadsafe
#        my $foo = $r->subprocess_env->get('FOO');
        my $foo = $ENV{FOO};
        $foo++;
        print "ok $foo\n";
    }

    Apache::OK;
}

1;
__END__
SetHandler perl-script
PerlResponseHandler TestApache::cgihandler


{'fraction_non_alphanumeric': 0.14635231316725977, 'fraction_numerical': 0.006227758007117438, 'mean_word_length': 2.805414551607445, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4993829', 'n_tokens_mistral': 818, 'n_tokens_neox': 781, 'n_words': 228}