line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::MountPSGI; |
2
|
7
|
|
|
7
|
|
64742
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
7
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
59
|
|
3
|
7
|
|
|
7
|
|
5525
|
use Mojolicious::Plugin::MountPSGI::Proxy; |
|
7
|
|
|
|
|
25
|
|
|
7
|
|
|
|
|
129
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.15'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub register { |
9
|
11
|
|
|
11
|
1
|
91859
|
my ($self, $app, $conf) = @_; |
10
|
|
|
|
|
|
|
|
11
|
11
|
|
|
|
|
42
|
my $rewrite = delete $conf->{rewrite}; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Extract host and path |
14
|
11
|
|
|
|
|
50
|
my $prefix = (keys %$conf)[0]; |
15
|
11
|
|
|
|
|
28
|
my ($host, $path); |
16
|
11
|
50
|
|
|
|
96
|
if ($prefix =~ /^(\*\.)?([^\/]+)(\/.*)?$/) { |
17
|
0
|
|
|
|
|
0
|
$host = quotemeta $2; |
18
|
0
|
0
|
|
|
|
0
|
$host = "(?:.*\\.)?$host" if $1; |
19
|
0
|
|
|
|
|
0
|
$path = $3; |
20
|
0
|
0
|
|
|
|
0
|
$path = '/' unless defined $path; |
21
|
0
|
|
|
|
|
0
|
$host = qr/^$host$/i; |
22
|
|
|
|
|
|
|
} |
23
|
11
|
|
|
|
|
27
|
else { $path = $prefix } |
24
|
|
|
|
|
|
|
|
25
|
11
|
100
|
|
|
|
56
|
my %args = ( |
26
|
|
|
|
|
|
|
rewrite => $rewrite ? $path : undef, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
11
|
50
|
|
|
|
64
|
unless ($ENV{PLACK_ENV}) { |
30
|
11
|
|
|
|
|
69
|
$args{mode} = $app->mode; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
11
|
|
|
|
|
187
|
my $psgi = $conf->{$prefix}; |
34
|
11
|
100
|
|
|
|
36
|
if (ref $psgi) { |
35
|
1
|
|
|
|
|
3
|
$args{app} = $psgi; |
36
|
|
|
|
|
|
|
} else { |
37
|
10
|
50
|
|
|
|
409
|
unless (-r $psgi) { |
38
|
0
|
|
|
|
|
0
|
my $abs = $app->home->rel_file($psgi); |
39
|
0
|
0
|
|
|
|
0
|
$psgi = $abs if -r $abs; |
40
|
|
|
|
|
|
|
} |
41
|
10
|
|
|
|
|
47
|
$args{script} = $psgi; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
11
|
|
|
|
|
121
|
my $proxy = Mojolicious::Plugin::MountPSGI::Proxy->new(%args); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Generate route |
47
|
11
|
|
|
|
|
85493
|
my $route = $app->routes->any($path)->partial(1)->to(app => $proxy); |
48
|
11
|
50
|
|
|
|
4794
|
if ($host) { |
49
|
0
|
|
0
|
|
|
0
|
my $requires = $route->can('requires') || $route->can('over'); |
50
|
0
|
|
|
|
|
0
|
$route->$requires(host => $host); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
11
|
|
|
|
|
84
|
return $route; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
__END__ |