line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Tools::HTTP::Apps; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
219050
|
use strict; |
|
10
|
|
|
|
|
36
|
|
|
10
|
|
|
|
|
279
|
|
4
|
10
|
|
|
10
|
|
52
|
use warnings; |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
217
|
|
5
|
10
|
|
|
10
|
|
1102
|
use URI; |
|
10
|
|
|
|
|
9196
|
|
|
10
|
|
|
|
|
5228
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: App container class for Test2::Tools::HTTP |
8
|
|
|
|
|
|
|
our $VERSION = '0.09'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
{ |
12
|
|
|
|
|
|
|
my $self; |
13
|
|
|
|
|
|
|
sub new |
14
|
|
|
|
|
|
|
{ |
15
|
106
|
|
100
|
106
|
1
|
6792
|
$self ||= bless { |
16
|
|
|
|
|
|
|
psgi => {}, |
17
|
|
|
|
|
|
|
base_url => undef, |
18
|
|
|
|
|
|
|
}, __PACKAGE__; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub uri_key |
24
|
|
|
|
|
|
|
{ |
25
|
156
|
|
|
156
|
1
|
322
|
my(undef, $uri) = @_; |
26
|
156
|
100
|
|
|
|
447
|
$uri = URI->new($uri) unless ref $uri; |
27
|
156
|
|
|
|
|
23539
|
join ':', map { $uri->$_ } qw( scheme host port ); |
|
468
|
|
|
|
|
7406
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub add_psgi |
32
|
|
|
|
|
|
|
{ |
33
|
22
|
|
|
22
|
1
|
54
|
my($self, $uri, $app) = @_; |
34
|
22
|
|
|
|
|
57
|
my $key = $self->uri_key($uri); |
35
|
22
|
|
|
|
|
720
|
$self->{psgi}->{$key} = { |
36
|
|
|
|
|
|
|
app => $app, |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub del_psgi |
42
|
|
|
|
|
|
|
{ |
43
|
13
|
|
|
13
|
1
|
30
|
my($self, $uri) = @_; |
44
|
13
|
|
|
|
|
28
|
my $key = $self->uri_key($uri); |
45
|
13
|
|
|
|
|
415
|
delete $self->{psgi}->{$key}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub base_url |
50
|
|
|
|
|
|
|
{ |
51
|
179
|
|
|
179
|
1
|
332
|
my($self, $new) = @_; |
52
|
|
|
|
|
|
|
|
53
|
179
|
100
|
|
|
|
417
|
if($new) |
54
|
|
|
|
|
|
|
{ |
55
|
3
|
50
|
|
|
|
14
|
$self->{base_url} = ref $new ? $new : URI->new($new); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
179
|
100
|
|
|
|
1456
|
unless(defined $self->{base_url}) |
59
|
|
|
|
|
|
|
{ |
60
|
6
|
|
|
|
|
39
|
$self->{base_url} = URI->new('http://localhost/'); |
61
|
6
|
|
|
|
|
23969
|
require IO::Socket::INET; |
62
|
6
|
|
|
|
|
82549
|
$self->{base_url}->port(IO::Socket::INET->new(Listen => 5, LocalAddr => "127.0.0.1")->sockport); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
179
|
|
|
|
|
3876
|
$self->{base_url}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub uri_to_app |
70
|
|
|
|
|
|
|
{ |
71
|
84
|
|
|
84
|
1
|
667
|
my($self, $uri) = @_; |
72
|
84
|
|
|
|
|
176
|
my $url = URI->new_abs($uri, $self->base_url); |
73
|
84
|
|
|
|
|
9574
|
my $key = $self->uri_key($url); |
74
|
84
|
|
|
|
|
2530
|
$self->{psgi}->{$key}->{app}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub uri_to_tester |
79
|
|
|
|
|
|
|
{ |
80
|
37
|
|
|
37
|
1
|
292
|
my($self, $uri) = @_; |
81
|
37
|
|
|
|
|
82
|
my $url = URI->new_abs($uri, $self->base_url); |
82
|
37
|
|
|
|
|
3628
|
my $key = $self->uri_key($url); |
83
|
37
|
|
|
|
|
970
|
my $app = $self->{psgi}->{$key}->{app}; |
84
|
37
|
50
|
|
|
|
98
|
return unless $app; |
85
|
|
|
|
|
|
|
|
86
|
37
|
|
66
|
|
|
186
|
$self->{psgi}->{$key}->{tester} ||= do { |
87
|
20
|
|
|
|
|
2499
|
require Plack::Test; |
88
|
20
|
|
|
|
|
3099
|
Plack::Test->create($app); |
89
|
|
|
|
|
|
|
}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |