Skip to content

Commit 5a49f8b

Browse files
author
Jarkko Haapalainen
committed
IO::Socket::Async server example using heredoc
and maybe more clearer for newcomers
1 parent 2222abe commit 5a49f8b

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

doc/Type/IO/Socket/Async.pod6

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,28 @@ http server that listens on port 3333:
1515
=begin code :skip-test<IO>
1616
react {
1717
whenever IO::Socket::Async.listen('0.0.0.0', 3333) -> $conn {
18-
whenever $conn.Supply.lines {
19-
say .Str;
20-
21-
{ try $conn.print(.Str ~ "\n") } for
22-
"HTTP/1.1 200 OK",
23-
"Content-Type: text/html; charset=UTF-8",
24-
"Content-Encoding: UTF-8",
25-
"",
26-
"<html><body>Hello World!</body></html>";
27-
18+
whenever $conn.Supply.lines -> $line {
19+
$conn.print: qq:heredoc/END/;
20+
HTTP/1.1 200 OK
21+
Content-Type: text/html; charset=UTF-8
22+
Content-Encoding: UTF-8
23+
24+
<html>
25+
<body>
26+
<h1>Hello World!</h1>
27+
<p>{ $line }</p>
28+
</body>
29+
</html>
30+
END
2831
$conn.close;
2932
}
30-
CLOSE {
31-
note „{now} connection closed“;
33+
}
34+
CATCH {
35+
default {
36+
say .^name, ': ', .Str;
37+
say "handled in $?LINE";
3238
}
3339
}
34-
CATCH { default { say .^name, ': ', .Str; say "handled in $?LINE"; } }
3540
}
3641
=end code
3742

0 commit comments

Comments
 (0)