NAME

HTTP::Daemon::App - Create 2 or 3 line, fully functional (SSL) HTTP server(s)

SYNOPSIS

use HTTP::Daemon::App;
use MyServers::Foo;
HTTP::Daemon::App::run($MyServers::Foo::daemons, $MyServers::Foo::config);

DESCRIPTION

You can describe one or more HTTP daemons in a simple hash and *instantly* have a [--start|--stop|--restart] capable daemon that can optionally be SSL aware.

Its also easy to add command line options and has integrated help.

EXPORT

Each function can be exported but nothing is by default.

FUNCTIONS

run

Takes 2 arguments, both hashrefs. The first describes tha daemons to run, the second is for config.

daemon hashref

Hopefully these are self descriptive, this example does two daemons SSL and non-SSL:

{
    'thingy-ssl' => {
        'label'   => 'HTTPS Thingy',
        'ssl'     => 1, # true: HTTP::Daemon::SSL, false: HTTP::Daemon
        'daemon'  => {
            # arguments HTTP::Daemon[::SSL]->new()
            'LocalPort' => 4279,
        },
        'handler' => sub {
            my($d, $c, $r) = @_; # $d, $c, $r from HTTP::Daemon
            # handle request
        },
    },
    'thingy' => {
        'label'   => 'HTTP Thingy',
        'ssl'     => 0, # true: HTTP::Daemon::SSL, false: HTTP::Daemon
        'daemon'  => {
            # arguments HTTP::Daemon[::SSL]->new()
            'LocalPort' => 4278,
        },
        'handler' => sub {
            my($d, $c, $r) = @_; # $d, $c, $r from HTTP::Daemon
            # handle request
        },
    },
},

config hashref

{
    'pid_dir' => '/var/run/', # default shown
    'pid_ext' => '.pid', # default shown
    'verbose' => 0, # example of your custom option that can be used by your handlers and set via 'opts' like below
    # 'lang'    => 'Locale::Maketext::Utils handle', not used yet
    'help'    => '', # default shown, this is added to the useage output.
    'opts'    => {
        # default {}, cannot use --stop, --start, or --restart, automagically added to useage line
        '--version'  => sub { print "$0 v1.0\n" },
        '--verbose' => sub { my($daemons_hashref, $conf) = @_;$conf->{'verbose'} = 1; },
    },
    'self' => "perl $0", # default shown, command used to call --stop & --start on --restart
}

decode_basic_auth

Given the encoded basic auth passed by the browser this will return the username an password.

my ($auth_user, $auth_pass) = decode_basic_auth( $encoded_basic_auth_from_browser );
my($user, $encpass, $uid, $gid, $homedir) = (getpwnam($auth_user))[0, 1, 2, 3, 7];

if($auth_user && $encpass eq crypt($auth_pass, $encpass) && $user eq $auth_user) {
    ... # continue on as authenticated user

SEE ALSO

HTTP::Daemon

AUTHOR

Daniel Muey, http://drmuey.com/cpan_contact.pl

COPYRIGHT AND LICENSE

Copyright (C) 2006 by Daniel Muey

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.