View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Adam Kennedy > POE-Declare-HTTP-Server-0.05 > POE::Declare::HTTP::Server



Annotate this POD

View/Report Bugs
Module Version: 0.05   Source  


POE::Declare::HTTP::Server - A simple HTTP server based on POE::Declare


    # Create the web server
    my $http = POE::Declare::HTTP::Server->new(
        Hostname => '',
        Port     => '8010',
        Handler  => sub {
            my $server   = shift;
            my $response = shift;
            # The request is not passed to you but is available if needed
            my $request = $response->request;
            # Webby content generation stuff here
            $response->code( 200 );
            $response->header( 'Content-Type' => 'text/plain' );
            $response->content( "Hello World!" );
    # Control with methods


This module provides a simple HTTP server based on POE::Declare.

The implemenetation is intentionally minimalist, making this module an ideal choice for creating specialised web servers embedded in larger applications.



    my $server = POE::Declare::HTTP::Server->new(
        Hostname      => '',
        Port          => '8010',
        Handler       => \&content,

        StartupEvent  => \&startup_done,
        StartupError  => \&startup_failed,
        ShutdownEvent => \&shutdown_done,

The new constructor sets up a reusable HTTP server that can be enabled and disabled repeatedly as needed.

It takes three required parameters parameters. Hostname, Port and Handler.

The Handler parameter should be a CODE reference that will be passed the server object and a HTTP::Response object. Your code should fill the provided response object, which will be sent to the client when the function ends. If your content will change based on the request, you can obtain the request from the "request" in HTTP::Response method.

The server supports three messages you can register callbacks for.

The StartupEvent message fires after the server socket has been bound and is available for clients to make requests, and before any connections have been made from clients.

The StartupError message fires if the server fails to bind to the port, or has some other error during the socket setup process.

The ShutdownEvent message fires on the completion of a controlled shutdown.

There is currently no ShutdownError event for unexpected server termination, as this should not occur. An error of this type may, however, be added later.


The Hostname accessor returns the server to bind to, as originally provided to the constructor.


The Port accessor returns the port number to bind to, as originally provided to the constructor.


The Handler accessor returns the CODE reference that requests will be passed to, as provided to the constructor.


The start method enables the web server. If the server is already running, this method will shortcut and do nothing.

If called before POE has been started, the web server will start immediately once POE is running.


The stop method disables the web server. If the server is not running, this method will shortcut and do nothing.


Bugs should be always be reported via the CPAN bug tracker at

For other issues, or commercial enhancement or support, contact the author.


Adam Kennedy <>




Copyright 2006 - 2011 Adam Kennedy.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

syntax highlighting: