line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!perl |
2
|
|
|
|
|
|
|
package Test::WWW::Declare::Tester::Server; |
3
|
14
|
|
|
14
|
|
12878
|
use strict; |
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
1411
|
|
4
|
14
|
|
|
14
|
|
75
|
use warnings; |
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
847
|
|
5
|
14
|
|
|
14
|
|
72
|
use base 'HTTP::Server::Simple::CGI'; |
|
14
|
|
|
|
|
23
|
|
|
14
|
|
|
|
|
14324
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my %content = ( |
8
|
|
|
|
|
|
|
index => << "INDEX", |
9
|
|
|
|
|
|
|
This is an index |
10
|
|
|
|
|
|
|
good link |
11
|
|
|
|
|
|
|
bad link |
12
|
|
|
|
|
|
|
same good link |
13
|
|
|
|
|
|
|
INDEX |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
good => << "GOOD", |
16
|
|
|
|
|
|
|
This is a good page |
17
|
|
|
|
|
|
|
index |
18
|
|
|
|
|
|
|
bad link |
19
|
|
|
|
|
|
|
infinite recursion |
20
|
|
|
|
|
|
|
GOOD |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
formy => << "FORMY", |
23
|
|
|
|
|
|
|
This page has two forms! |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
FORMY |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
result1 => sub { |
35
|
|
|
|
|
|
|
my $cgi = shift; my $clever = $cgi->param('clever'); |
36
|
|
|
|
|
|
|
return "\U$clever\E"; |
37
|
|
|
|
|
|
|
}, |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
result2 => sub { |
40
|
|
|
|
|
|
|
my $cgi = shift; my $clever = $cgi->param('clever'); |
41
|
|
|
|
|
|
|
return "\L$clever\E"; |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub wrap_content |
47
|
|
|
|
|
|
|
{ |
48
|
0
|
|
|
0
|
|
0
|
my ($url, $content) = @_; |
49
|
0
|
|
|
|
|
0
|
$content =~ s/^/ /mg; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
$content = << "WRAPPER"; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
\U$url\E |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$content |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
WRAPPER |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
return $content; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub get { |
66
|
0
|
|
|
0
|
|
0
|
my $page = (split '/', shift)[-1]; |
67
|
0
|
|
0
|
|
|
0
|
$page ||= 'index'; |
68
|
0
|
|
|
|
|
0
|
$page =~ s/\s+//g; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
my $content = $content{$page}; |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
0
|
return if !defined($content); |
73
|
0
|
0
|
|
|
|
0
|
return wrap_content($page, $content->(@_)) if ref($content) eq 'CODE'; |
74
|
0
|
|
|
|
|
0
|
return wrap_content($page, $content); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub handle_request { |
78
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
79
|
0
|
|
|
|
|
0
|
my $cgi = shift; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
0
|
if (my $content = get($cgi->path_info, $cgi)) { |
82
|
0
|
|
|
|
|
0
|
print "HTTP/1.0 200 OK\r\n"; |
83
|
0
|
|
|
|
|
0
|
print "Content-Type: text/html\r\nContent-Length: ", |
84
|
|
|
|
|
|
|
length($content), |
85
|
|
|
|
|
|
|
"\r\n\r\n", |
86
|
|
|
|
|
|
|
$content; |
87
|
0
|
|
|
|
|
0
|
return; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
0
|
print "HTTP/1.0 404 Not Found\r\n\r\n"; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
package Test::WWW::Declare::Tester; |
94
|
14
|
|
|
14
|
|
508211
|
use Test::Tester; |
|
14
|
|
|
|
|
289237
|
|
|
14
|
|
|
|
|
97
|
|
95
|
14
|
|
|
14
|
|
12306
|
use Test::WWW::Declare; |
|
14
|
|
|
|
|
51
|
|
|
14
|
|
|
|
|
202
|
|
96
|
14
|
|
|
14
|
|
3596
|
use base 'Test::More'; |
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
3927
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
99
|
|
|
|
|
|
|
our @EXPORT = qw($PORT $SERVER $PID); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
our $PORT = 12321; |
102
|
|
|
|
|
|
|
our $SERVER = Test::WWW::Declare::Tester::Server->new($PORT); |
103
|
|
|
|
|
|
|
our $PID = $SERVER->background or die "Cannot start the server"; |
104
|
|
|
|
|
|
|
sleep 1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub import_extra { |
107
|
14
|
|
|
14
|
1
|
16528
|
Test::Tester->export_to_level(2); |
108
|
14
|
|
|
|
|
10097
|
Test::WWW::Declare->export_to_level(2); |
109
|
14
|
|
|
|
|
9004
|
Test::More->export_to_level(2); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
END { |
113
|
14
|
|
|
14
|
|
100145
|
kill(9, $PID); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
|