File Coverage

blib/lib/Mojolicious/Plugin/VHost.pm
Criterion Covered Total %
statement 15 15 100.0
branch 1 2 50.0
condition 1 2 50.0
subroutine 3 3 100.0
pod 1 1 100.0
total 21 23 91.3


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::VHost;
2 1     1   8236 use Mojo::Base 'Mojolicious::Plugin';
  1         2  
  1         6  
3              
4             our $VERSION = '0.04';
5              
6             sub register {
7 1     1 1 33 my ($plugin, $app) = @_;
8              
9 1         34 my %defaults = (
10             routes => $app->routes->namespaces,
11             static => $app->static->paths,
12             templates => $app->renderer->paths,
13             );
14              
15             $app->hook(
16             before_dispatch => sub {
17 1     1   36138 my $c = shift;
18              
19 1         24 my $host = $c->tx->req->headers->host;
20              
21 1   50     117 my $hosts = $c->app->config('VHost') || {};
22 1 50       28 my %conf = ( %defaults, %{$hosts->{$host} || {}} );
  1         80  
23              
24 1         28 my $app = $c->app;
25 1         30 $app->routes->namespaces($conf{routes});
26 1         57 $app->static->paths($conf{static});
27 1         56 $app->renderer->paths($conf{templates});
28             }
29 1         271 );
30             }
31              
32             1;
33             __END__