NAME
Any::Daemon::HTTP::VirtualHost - webserver virtual hosts
SYNOPSIS
my $vhost = Any::Daemon::HTTP::VirtualHost->new(@vhost_opts);
my $daemon = Any::Daemon::HTTP->new
( @other_options
, vhosts => $vhost # or \@vhosts
);
# or
my $daemon = Any::Daemon::HTTP->new(@other_opts);
$daemon->addVirtualHost($vhost);
$daemon->addVirtualHost(@vhost2_opts);
# create object which extends Any::Daemon::HTTP::VirtualHost
my $myvhost = MyVHost->new(...);
$daemon->addVirtualHost($myvhost);
DESCRIPTION
These virtual host definitions are used by Any::Daemon::HTTP, to implement (server) name based data seperation. Its features resemble those of Apache virtual hosts.
Each virtual host usually has to Any::Daemon::HTTP::Directory slaves: one which describes the permissions for user directories (url paths in the form /~user/
) and one for data outside the user space.
METHODS
Constructors
You may avoid the creation of extension classes for each virtual host, by using these options.
- Any::Daemon::HTTP::VirtualHost->new(OPTIONS|HASH-of-OPTIONS)
-
-Option --Default aliases [] directories <see text> documents <undef> handlers {} name <required> rewrite <undef> user_dirs undef
- aliases => HOSTNAME|ARRAY-of-HOSTNAMES
- directories => OBJECT|HASH|ARRAY
-
Pass one or more Any::Daemon::HTTP::Directory OBJECTS, or HASHes which will be used to initialize them.
- documents => DIRECTORY
-
An absolute DIRECTORY for the location of the source files. Creates the most free Any::Daemon::HTTP::Directory object. If you need things like access restrictions, then do not use this option but the
directories
option. - handlers => CODE|HASH
-
The keys are path names, part of the request URIs. The values are CODE-references, called when that URI is addressed. The access rules are taken from the directory definition which is selected by the path, for that's all.
The handlers are called with a the client, the request (HTTP::Request), uri object (URI).
- name => HOSTNAME
- rewrite => CODE
-
See rewrite().
- user_dirs => undef|OBJECT|HASH
-
With an (empty?) HASH which contains instantiation parameter, an Any::Daemon::HTTP::UserDirs is created for you, with standard Apache behavior. You may provide your own OBJECT. Without this parameter, there are no public user pages.
Attributes
- $obj->aliases()
-
Returns a list of all aliases (alternative names) for this server.
- $obj->name()
-
Returns the primary name for this server.
Handler
- $obj->addHandler(CODE|(PATH => CODE)-LIST|HASH)
-
When only CODE is set, then this will be the default handler for all paths (under '/', top). You may also pass a list or HASH of PAIRS.
example:
$vhost->addHandler('/' => \&default_handler, '/upload' => \&upload_handler); $vhost->addHandler(\&default_handler);
- $obj->findHandler(URI|PATH|PATH-SEGMENTS)
Access permissions
Basic daemon actions
- $obj->allow(SESSION, REQUEST, URI)
-
BE WARNED that the URI is the rewrite of the REQUEST uri, and therefore you should use that URI. The SESSION represents a user.
See "Allow access".
- $obj->rewrite(URI)
-
Returns an URI object as result, which may be the original in case of no rewrite was needed. See "URI Rewrite".
Directories
- $obj->addDirectory(OBJECT|HASH|OPTIONS)
-
Either pass a Any::Daemon::HTTP::Directory OBJECT or the OPTIONS to create the object. When OPTIONS are provided, they are passed to Any::Daemon::HTTP::Directory::new() to create the OBJECT.
- $obj->directoryOf(PATH|PATH_SEGMENTS)
-
Find the best matching Any::Daemon::HTTP::Directory object.
- $obj->filename(URI)
-
Translate the URI into a filename, without checking for existence. Returns
undef
is not possible.
DETAILS
URI Rewrite
For each request, the rewrite() method is called to see whether a rewrite of the URI is required. The method must return the original URI object (the only parameter) or a new URI object.
SEE ALSO
This module is part of Any-Daemon-HTTP distribution version 0.20, built on October 11, 2013. Website: http://perl.overmeer.net/any-daemon/
LICENSE
Copyrights 2013 by [Mark Overmeer]. For other contributors see ChangeLog.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html