line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Apache2::Server; |
2
|
5
|
|
|
5
|
|
63309
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
146
|
|
3
|
5
|
|
|
5
|
|
25
|
use warnings; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
139
|
|
4
|
5
|
|
|
5
|
|
24
|
use base qw(Class::Accessor::Fast); |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
4041
|
|
5
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(host)); |
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
19144
|
use Test::Apache2::RequestRec; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use HTTP::Response; |
9
|
|
|
|
|
|
|
use attributes (); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
|
|
|
|
|
|
my ($class, @args) = @_; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $self = $class->SUPER::new(@args); |
15
|
|
|
|
|
|
|
$self->{handlers} = []; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
if (! $self->host) { |
18
|
|
|
|
|
|
|
$self->host('example.com'); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub location { |
25
|
|
|
|
|
|
|
my ($self, $path, $config_ref) = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
unshift @{ $self->{handlers} }, { |
28
|
|
|
|
|
|
|
path => $path, |
29
|
|
|
|
|
|
|
handler => $config_ref->{PerlResponseHandler}, |
30
|
|
|
|
|
|
|
config => $config_ref |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub request { |
35
|
|
|
|
|
|
|
my ($self, $req) = @_; |
36
|
|
|
|
|
|
|
$self->_request(Test::Apache2::RequestRec->new($req)); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub get { |
40
|
|
|
|
|
|
|
my ($self, $path) = @_; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $req = Test::Apache2::RequestRec->new({ |
43
|
|
|
|
|
|
|
method => 'GET', uri => 'http://' . $self->host . $path, |
44
|
|
|
|
|
|
|
headers_in => {} |
45
|
|
|
|
|
|
|
}); |
46
|
|
|
|
|
|
|
$self->_request($req); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _select { |
50
|
|
|
|
|
|
|
my ($self, $path) = @_; |
51
|
|
|
|
|
|
|
for my $hash_ref (@{ $self->{handlers} }) { |
52
|
|
|
|
|
|
|
my $index = index $path, $hash_ref->{path}; |
53
|
|
|
|
|
|
|
if (defined $index && $index == 0) { |
54
|
|
|
|
|
|
|
return $path, $hash_ref->{handler}, $hash_ref->{config}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
return; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _request { |
62
|
|
|
|
|
|
|
my ($self, $req) = @_; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my ($location, $class, $config) = $self->_select($req->path); |
65
|
|
|
|
|
|
|
$req->location($location); |
66
|
|
|
|
|
|
|
$req->dir_config($config); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $buffer = ''; |
69
|
|
|
|
|
|
|
{ |
70
|
|
|
|
|
|
|
local *STDOUT; |
71
|
|
|
|
|
|
|
open STDOUT, '>', \$buffer; |
72
|
|
|
|
|
|
|
my $handler = $class->can('handler'); |
73
|
|
|
|
|
|
|
if (grep { $_ eq 'method' } attributes::get($handler)) { |
74
|
|
|
|
|
|
|
$class->$handler($req); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
else { |
77
|
|
|
|
|
|
|
$handler->($req); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
if ($buffer) { |
82
|
|
|
|
|
|
|
$req->print($buffer); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
return $req->to_response; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
__END__ |