blib/lib/Mojolicious/Plugin/AutoIndex.pm

filter: Statementstmt 100% 29 / 29 Branchbran 87.5% 7 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 89.5% 43 / 48 CC 7 SCAR 12.2
CC
7
Cov
92%
__ANON__
5.0
register
3.0
BEGIN
1.0
CRAP 3.4
↑ Summary
1 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 # ABSTRACT: Mojolicious plugin for autoindex function at static resource
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Mojolicious::Plugin::AutoIndex;
7 {
8 6 $Mojolicious::Plugin::AutoIndex::VERSION = '0.0006';
9 }
10  
11 6 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 6 my $config = { index => [qw/index.html index.htm/] };
15  
16 5 ▶sub register {
Subroutine register: called CC=3 SCAR=11.0
Pod documented
17 5 my ( $self, $app, $conf ) = @_;
18 5 ▶ $config->{index} = $conf->{index} if $conf->{index};
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"index"} 4 1 5
19 5 ▶ return unless @{ $config->{index} };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$config->{"index"};} 0 5 5
20 $app->hook(
21 8 ▶ before_dispatch => sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
22 8 my $c = shift;
23 8 ▶ my $path = $c->stash('path') // $c->req->url->path->to_string;
Condition33%1/3
$c->stash("path") // $c->req->url->path->to_string
l!l&&r!l&&!r
080
MC/DC0%0/2
$c->stash("path") // $c->req->url->path->to_string
$c->stash("path") $c->req->url->path->to_string
Truth table33%1/3
A // B
A= $c->stash("path")B= $c->req->url->path->to_string
ABresult
1X1
011
000
24 8 ▶ return unless $path =~ m!/$!;
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ m[/$]u 3 5 8
25 5 my $sv_path = $c->stash('path');
26 5 foreach ( @{ $config->{index} } ) {
27 5 $c->stash->{path} = $path . $_;
28 5 ▶ if ( $app->static->dispatch($c) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->static->dispatch($c)) 3 2 5
29 3 $c->stash->{path} = $sv_path;
30 3 return $app->plugins->emit_hook( after_static => $c );
31 }
32 }
33 2 $c->stash->{path} = $sv_path;
34 }
35 5 );
36 }
37  
38 6 1;
39  
40 __END__
↑ Summary