File: subenv.pm

package info (click to toggle)
libapache2-mod-perl2 2.0.13-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 12,016 kB
  • sloc: perl: 97,771; ansic: 14,493; makefile: 51; sh: 18
file content (118 lines) | stat: -rw-r--r-- 2,534 bytes parent folder | download | duplicates (7)
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
# please insert nothing before this line: -*- mode: cperl; cperl-indent-level: 4; cperl-continued-statement-offset: 4; indent-tabs-mode: nil -*-
package TestModperl::subenv;

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

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

use Apache::Test;

use Apache2::Const -compile => 'OK';

sub handler {

    my $r = shift;

    plan $r, tests => 31;

    # subprocess_env in void context with arguments does
    # nothing to %ENV
    {
        my $env = $r->subprocess_env;

        my $key = 'ONCE';

        ok_false($r, $key);

        $r->subprocess_env($key => 1); # void context but with args

        ok_true($r, $key);

        ok ! $ENV{$key};               # %ENV not populated yet
    }

    # subprocess_env in void context with no arguments
    # populates the same as +SetEnv
    {
        my $env = $r->subprocess_env;

        my $key = 'REMOTE_ADDR';

        ok_false($r, $key);   # still not not there yet

        ok ! $ENV{$key};      # %ENV not populated yet

        $r->subprocess_env;   # void context with no arguments

        ok_true($r, $key);

        ok $ENV{$key};        # mod_cgi emulation
    }

    # handlers can use a void context more than once to force
    # population of %ENV with new table entries
    {
        my $env = $r->subprocess_env;

        my $key = 'AGAIN';

        $env->set($key => 1);      # new table entry

        ok_true($r, $key);

        ok ! $ENV{$key};           # shouldn't affect %ENV yet

        $r->subprocess_env;        # now called in in void context twice

        ok $ENV{$key};             # so %ENV is populated with new entry
    }

    {
        my $env = $r->subprocess_env; # table may have been overlayed

        my $key = 'FOO';

        $env->set($key => 1);         # direct call to set()

        ok_true($r, $key);

        ok ! $ENV{$key};              # shouldn't affect %ENV

        $r->subprocess_env($key => undef);

        ok_false($r, $key);           # removed

        $r->subprocess_env($key => 1);

        ok_true($r, $key);            # reset

        ok ! $ENV{$key};              # still shouldn't affect %ENV
    }

    Apache2::Const::OK;
}

sub ok_true {
    my ($r, $key) = @_;

    my $env = $r->subprocess_env;
    ok $env->get($key);
    ok $env->{$key};
    ok $r->subprocess_env($key);
}

sub ok_false {
    my ($r, $key) = @_;

    my $env = $r->subprocess_env;
    ok ! $env->get($key);
    ok ! $env->{$key};
    ok ! $r->subprocess_env($key);
}

1;
__END__
PerlOptions -SetupEnv