Daniel Muey > HTTP-Daemon-App-v0.0.9 > HTTP::Daemon::App

Download:
HTTP-Daemon-App-v0.0.9.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  1
View/Report Bugs
Module Version: 0.0.9   Source  

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, $conf_hr) = @_; # $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, $conf_hr) = @_; # $d, $c, $r from HTTP::Daemon
                # handle request
            },
        },
    },

config hashref

    {
        'pre_fork' => '', # set to a code ref it gets called before it forks the child process,  its args are ($handler, $d, $name, $pidfile, $conf)
        'pst_fork' => '', # same as pre_fork but run after the fork is done
        '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 (or given the "$r" object from HTTP::Daemon, the 'Authorization' header's value) 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

send_basic_auth_request

Takes two arguments: the "$c" object from HTTP::Request, the realm's name (has lame default if not specified)

It does a 401 that incites the client's authentication challenge (E.g. a browser's drop down login box)

        ... # continue on as authenticated user
        }
        else {
            HTTP::Daemon::App::send_basic_auth_request($c, 'Vault of secrets');
        }

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.

syntax highlighting: