line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
5
|
|
|
5
|
|
5579
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
229
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Mojolicious plugin for autoindex function at static resource |
4
|
5
|
|
|
5
|
|
30
|
use warnings; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
13654
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Mojolicious::Plugin::AutoIndex; |
7
|
|
|
|
|
|
|
{ |
8
|
|
|
|
|
|
|
$Mojolicious::Plugin::AutoIndex::VERSION = '0.0006'; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
|
11
|
5
|
|
|
5
|
|
49
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
60
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $config = { index => [qw/index.html index.htm/] }; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub register { |
17
|
5
|
|
|
5
|
1
|
336
|
my ( $self, $app, $conf ) = @_; |
18
|
5
|
100
|
|
|
|
33
|
$config->{index} = $conf->{index} if $conf->{index}; |
19
|
5
|
50
|
|
|
|
11
|
return unless @{ $config->{index} }; |
|
5
|
|
|
|
|
27
|
|
20
|
|
|
|
|
|
|
$app->hook( |
21
|
|
|
|
|
|
|
before_dispatch => sub { |
22
|
8
|
|
|
8
|
|
274143
|
my $c = shift; |
23
|
8
|
|
33
|
|
|
56
|
my $path = $c->stash('path') // $c->req->url->path->to_string; |
24
|
8
|
100
|
|
|
|
3948
|
return unless $path =~ m!/$!; |
25
|
5
|
|
|
|
|
32
|
my $sv_path = $c->stash('path'); |
26
|
5
|
|
|
|
|
61
|
foreach ( @{ $config->{index} } ) { |
|
5
|
|
|
|
|
30
|
|
27
|
5
|
|
|
|
|
38
|
$c->stash->{path} = $path . $_; |
28
|
5
|
100
|
|
|
|
193
|
if ( $app->static->dispatch($c) ) { |
29
|
3
|
|
|
|
|
5479
|
$c->stash->{path} = $sv_path; |
30
|
3
|
|
|
|
|
98
|
return $app->plugins->emit_hook( after_static => $c ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
2
|
|
|
|
|
1563
|
$c->stash->{path} = $sv_path; |
34
|
|
|
|
|
|
|
} |
35
|
5
|
|
|
|
|
60
|
); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
1; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
__END__ |