virtualHosts.pl

#!/usr/bin/perl
use strict;
use warnings FATAL => qw(all);

use Sloop::Server;

# See 'virtualHosts' in Sloop::Server SYNOPSIS.

my %Hosts = (
    'localhost' => {
        '/' => sub {
            my $client = shift;
            $client->reply(\"<h1>localhost</h1>");
        }
    },
    'local2.here' => {
        '/' => sub {
            my $client = shift;
            $client->reply(\"<h1>local2</h1>");
        }
    },
    'default' => {
    # If you don't define this, this is what it will be.
        '/' => sub {
            my $client = shift;
            $client->generic(404);
        }
    }
);

my $Sloop = Sloop::Server->new (
    virtualHosts => \%Hosts
);
die if !$Sloop;

$Sloop->run();