line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mock::Apache2; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1819
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
69
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
81
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
2731
|
use Test::MockObject; |
|
2
|
|
|
|
|
46047
|
|
|
2
|
|
|
|
|
16
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: Mock mod_perl2 objects when running outside of Apache |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $AP2_REQ; |
14
|
|
|
|
|
|
|
our $AP2_REQ_UTIL; |
15
|
|
|
|
|
|
|
our $APR_REQ_AP2; |
16
|
|
|
|
|
|
|
our $APR_THROW_EXCEPTION = 0xDEADBEEF; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
{ |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $COOKIE_JAR = {}; |
21
|
|
|
|
|
|
|
my $PARAMS = {}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub cookie_jar { |
24
|
2
|
|
|
2
|
0
|
728
|
my $self = shift; |
25
|
|
|
|
|
|
|
|
26
|
2
|
100
|
|
|
|
7
|
if (@_) { |
27
|
1
|
|
|
|
|
2
|
$COOKIE_JAR = shift; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
5
|
return $COOKIE_JAR; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub params { |
34
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
0
|
if (@_) { |
37
|
0
|
|
|
|
|
0
|
$PARAMS = shift; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
0
|
return $PARAMS; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub import { |
46
|
2
|
|
|
2
|
|
21
|
my( $package, $config ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#arn "Init mocked objects...\n"; |
49
|
2
|
|
|
|
|
7
|
init_mocked_objects($config); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# XXX Apache2::Cookie |
52
|
2
|
|
|
|
|
5
|
my @modules_to_fake = qw( |
53
|
|
|
|
|
|
|
Apache2::Request |
54
|
|
|
|
|
|
|
Apache2::SubRequest |
55
|
|
|
|
|
|
|
Apache2::URI |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#arn "Faking modules...\n"; |
59
|
2
|
|
|
|
|
16
|
Test::MockObject->fake_module($_) for @modules_to_fake; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub ap2_server { |
64
|
1
|
|
|
1
|
1
|
3
|
my $config = shift; |
65
|
1
|
|
|
|
|
5
|
my $r = Test::MockObject->new(); |
66
|
|
|
|
|
|
|
$r->fake_module('Apache2::ServerRec', |
67
|
2
|
50
|
|
2
|
|
848
|
server_hostname => sub { $config->{server_hostname} || 'localhost' }, |
68
|
0
|
|
|
0
|
|
0
|
log_error => sub { print $_[0] . "\n"; }, |
69
|
1
|
|
|
|
|
14
|
); |
70
|
1
|
|
|
|
|
162
|
bless $r, 'Apache2::ServerRec'; |
71
|
1
|
|
|
|
|
4
|
return $r; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub ap2_request { |
76
|
4
|
|
|
4
|
1
|
7
|
my $config = shift; |
77
|
4
|
|
|
|
|
28
|
my $r = Test::MockObject->new(); |
78
|
|
|
|
|
|
|
$r->fake_module('Apache2::RequestRec', |
79
|
0
|
|
|
0
|
|
0
|
hostname => sub {}, |
80
|
1
|
|
|
1
|
|
4
|
server => sub { ap2_server($config) }, |
81
|
3
|
|
|
3
|
|
843
|
dir_config => sub { $config->{ $_[1] } }, |
82
|
0
|
|
|
0
|
|
0
|
content_type => sub { }, |
83
|
0
|
|
|
0
|
|
0
|
uri => sub { ""; }, |
84
|
4
|
|
|
|
|
93
|
); |
85
|
4
|
|
|
|
|
303
|
bless $r, 'Apache2::RequestRec'; |
86
|
4
|
|
|
|
|
12
|
return $r; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub apr_request_ap2 { |
91
|
3
|
|
|
3
|
0
|
1474
|
my $r = Test::MockObject->new(); |
92
|
|
|
|
|
|
|
$r->fake_module('APR::Request::Apache2', |
93
|
|
|
|
|
|
|
jar => sub { |
94
|
|
|
|
|
|
|
# Some primitive exception logic is needed |
95
|
|
|
|
|
|
|
# to simulate the cookie-containing-comma bug |
96
|
1
|
|
|
1
|
|
5
|
my $jar = Test::Mock::Apache2->cookie_jar(); |
97
|
1
|
50
|
33
|
|
|
8
|
if (! ref $jar and ($jar == $APR_THROW_EXCEPTION)) { |
98
|
0
|
|
|
|
|
0
|
my $apr_req_err = Test::MockObject->new(); |
99
|
0
|
|
|
|
|
0
|
$apr_req_err->fake_module('APR::Request::Error'); |
100
|
0
|
|
|
|
|
0
|
$apr_req_err->set_always(jar => \&cookie_jar); |
101
|
0
|
|
|
|
|
0
|
return $apr_req_err; |
102
|
|
|
|
|
|
|
} |
103
|
1
|
|
|
|
|
9
|
bless $jar, "APR::Request::Cookie::Table"; |
104
|
|
|
|
|
|
|
}, |
105
|
|
|
|
|
|
|
param => sub { |
106
|
0
|
|
|
0
|
|
0
|
my $params = Test::Mock::Apache2->params(); |
107
|
0
|
|
|
|
|
0
|
bless $params, "APR::Request::Param::Table"; |
108
|
|
|
|
|
|
|
}, |
109
|
3
|
|
|
|
|
178
|
handle => \&apr_request_ap2, |
110
|
|
|
|
|
|
|
); |
111
|
3
|
|
|
|
|
249
|
$r->fake_new('APR::Request::Apache2'); |
112
|
3
|
|
|
|
|
164
|
bless $r, 'APR::Request::Apache2'; |
113
|
3
|
|
|
|
|
7
|
return $r; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub ap2_requestutil { |
118
|
2
|
|
|
2
|
1
|
10
|
my $config = shift; |
119
|
2
|
|
|
|
|
8
|
my $ap2_ru = Test::MockObject->new(); |
120
|
|
|
|
|
|
|
$ap2_ru->fake_module('Apache2::RequestUtil', |
121
|
2
|
|
|
2
|
|
20
|
request => sub { ap2_request($config) }, |
122
|
3
|
|
|
3
|
|
1423
|
dir_config => sub { $config->{ $_[1] } }, |
123
|
2
|
|
|
|
|
21
|
); |
124
|
2
|
|
|
|
|
102
|
$ap2_ru->fake_new('Apache2::RequestUtil'); |
125
|
2
|
|
|
|
|
59
|
bless $ap2_ru, 'Apache2::RequestUtil'; |
126
|
2
|
|
|
|
|
20
|
return $ap2_ru; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub init_mocked_objects { |
131
|
2
|
|
100
|
2
|
1
|
49
|
my $config = shift || {}; |
132
|
|
|
|
|
|
|
|
133
|
2
|
|
|
|
|
11
|
$AP2_REQ = ap2_request($config); |
134
|
2
|
|
|
|
|
22
|
$APR_REQ_AP2 = apr_request_ap2(); |
135
|
2
|
|
|
|
|
7
|
$AP2_REQ_UTIL = ap2_requestutil($config); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
__END__ |