Mojolicious::Plugin::Mount - Application Mount Plugin


Mojolicious documentation Contained in the Mojolicious distribution.

Index


Code Index:

NAME

Top

Mojolicious::Plugin::Mount - Application Mount Plugin

SYNOPSIS

Top

  # Mojolicious
  $self->plugin(mount => {'/prefix' => '/home/sri/myapp.pl'});

  # Mojolicious::Lite
  plugin mount => {'/prefix' => '/home/sri/myapp.pl'};

  # Adjust the generated route
  my $example = plugin mount => {'/example' => '/home/sri/example.pl'};
  $example->to(message => 'It works great!');

  # Mount application with host (automatically disables route caching)
  plugin mount => {'mojolicio.us' => '/home/sri/myapp.pl'};

  # Host and path
  plugin mount => {'mojolicio.us/myapp' => '/home/sri/myapp.pl'};

  # Or even hosts with wildcard subdomains
  plugin mount => {'*.mojolicio.us/myapp' => '/home/sri/myapp.pl'};

DESCRIPTION

Top

Mojolicious::Plugin::Mount is a plugin that allows you to mount whole Mojolicious applications. Note that this module is EXPERIMENTAL and might change without warning!

METHODS

Top

Mojolicious::Plugin::Mount inherits all methods from Mojolicious::Plugin and implements the following new ones.

register

  $plugin->register;

Mount Mojolicious application.

SEE ALSO

Top

Mojolicious, Mojolicious::Guides, http://mojolicio.us.


Mojolicious documentation Contained in the Mojolicious distribution.

package Mojolicious::Plugin::Mount;
use Mojo::Base 'Mojolicious::Plugin';

use Mojo::Server;

sub register {
  my ($self, $app, $conf) = @_;

  # Extract host and path
  my $prefix = (keys %$conf)[0];
  my ($host, $path);
  if ($prefix =~ /^(\*\.)?([^\/]+)(\/.*)?$/) {
    $host = quotemeta $2;
    $host = "(?:.*\\.)?$host" if $1;
    $path = $3;
    $path = '/' unless defined $path;
    $host = qr/^$host$/i;
    $app->routes->cache(0);
  }
  else { $path = $prefix }

  # Generate route
  my $route =
    $app->routes->route($path)
    ->detour(app => Mojo::Server->new->load_app($conf->{$prefix}));
  $route->over(host => $host) if $host;

  $route;
}

1;
__END__