Hello world/Web server: Difference between revisions

Perl examples with Plack::Runner and plackup
(Perl examples with Plack::Runner and plackup)
Line 680:
close $client;
}</lang>
Here's another solution using Plack (may be found on CPAN):
<lang Perl>use Plack::Runner;
my $app = sub { return [ 200, [ 'Content-Type' => 'text/html; charset=UTF-8' ], [ '<html><head><title>Goodbye, world!</title></head><body>Goodbye, world!</body></html>' ] ] };
my $runner = Plack::Runner->new->run($app);</lang>
 
When using plackup, then this may be compressed to one line:
<lang perl>my $app = sub { return [ 200, [ 'Content-Type' => 'text/html; charset=UTF-8' ], [ '<html><head><title>Goodbye, world!</title></head><body>Goodbye, world!</body></html>' ] ] };</lang>
Use "plackup script.psgi" to start the webserver.
 
Using Perl's glue power, provide a suicide note with visitor counter via netcat:
<lang Perl>while (++(our $vn)) {
Anonymous user