Mojolicious::Plugin::VHost - Mojolicious Plugin that adds VirtualHosts
# Mojolicious $self->plugin('JSONConfig'); $self->plugin('VHost');
Mojolicious::Plugin::VHost adds virtualhosts to Mojolicious.
One supported method of configuration is with the JSONConfig plugin. Add vhosts with a config such as:
{ "VHost": { "host1":{"routes":["VHost::First::Controller"],"static":["public\/first"],"templates":["templates\/first"]}, "host2":{"routes":["VHost::Another::Controller"],"static":["public\/another"],"templates":["templates\/another"]} } }
host1 and host2 are the Host: header field and must match exactly. The following route format has been tested:
$r->get('/')->to(controller => 'Index', action => 'slash'); $r->get('/:name')->to(controller => 'Index', action => 'slash');
For host1, "/" would route to lib/VHost/First/Index.pm; static files would be in public/first; and templates would be found in templates/first.
A full startup sub is:
sub startup { my $self = shift; $self->plugin('JSONConfig'); $self->plugin('VHost'); # Router my $r = $self->routes; $r->get('/')->to(controller => 'Index', action => 'slash'); $r->get('/:name')->to(controller => 'Index', action => 'slash'); }
Mojolicious::Plugin::VHost inherits all methods from Mojolicious::Plugin and implements the following new ones.
$plugin->register(Mojolicious->new);
Register plugin in Mojolicious application.
Mojolicious, Mojolicious::Guides, http://mojolicio.us.
To install Mojolicious::Plugin::VHost, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::VHost
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::VHost
For more information on module installation, please visit the detailed CPAN module installation guide.