lib/Plack/Middleware/DirIndex.pm

filter: Statementstmt 100% 23 / 23 Branchbran 83.3% 5 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 97.6% 42 / 43 CC 5 SCAR 7.4
CC
5
Cov
97%
prepare_app
3.0
call
3.0
BEGIN
1.0
CRAP 2.1
↑ Summary
1 package Plack::Middleware::DirIndex;
2 2 $Plack::Middleware::DirIndex::VERSION = '1.01';
3 # ABSTRACT: Append an index file to request PATH's ending with a /
4  
5 2 ▶use parent qw( Plack::Middleware );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Plack::Util::Accessor qw(dir_index root);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Plack::Middleware::DirIndex - Middleware to use with Plack::App::Directory and the like
14  
15 =head1 SYNOPSIS
16  
17 use Plack::Builder;
18 use Plack::App::File;
19 use Plack::Middleware::DirIndex;
20  
21 my $app = Plack::App::File->new({ root => './htdocs/' })->to_app;
22  
23 builder {
24 enable "Plack::Middleware::DirIndex", dir_index => 'index.html';
25 $app;
26 }
27
28 =head1 DESCRIPTION
29  
30 If $env->{PATH_INFO} ends with a '/' then we will append the dir_index
31 value to it (defaults to index.html)
32  
33 =head1 COPYRIGHT & LICENSE
34  
35 Copyright (c) 2012 Leo Lapworth. All rights reserved.
36 This program is free software; you can redistribute
37 it and/or modify it under the same terms as Perl itself.
38  
39 =cut
40  
41 4 ▶sub prepare_app {
Subroutine prepare_app: called CC=3 SCAR=11.1
Pod documented
42 4 my ($self) = @_;
43  
44 4 ▶ $self->root('.') unless $self->root;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->root 0 4 4
45 4 ▶ $self->dir_index('index.html') unless $self->dir_index;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->dir_index 2 2 4
46 }
47  
48 10 ▶sub call {
Subroutine call: called CC=3 SCAR=11.0
Pod documented
49 10 my ( $self, $env ) = @_;
50  
51 10 ▶ if ( $env->{PATH_INFO} =~ m{/$}
Branch: 1 branch
BranchTrueFalseTotal
if ($env->{"PATH_INFO"} =~ m[/$] and -f $self->root . '/' . $env->{"PATH_INFO"} . $self->dir_index) 4 6 10
Condition100%3/3
$env->{"PATH_INFO"} =~ m[/$] and -f $self->root . '/' . $env->{"PATH_INFO"} . $self->dir_index
!ll&&!rl&&r
244
MC/DC100%2/2
$env->{"PATH_INFO"} =~ m[/$] and -f $self->root . '/' . $env->{"PATH_INFO"} . $self->dir_index
$env->{"PATH_INFO"} =~ m[/$] -f $self->root . '/' . $env->{"PATH_INFO"} . $self->dir_index
Truth table100%3/3
A and B
A= $env->{"PATH_INFO"} =~ m[/$]B= -f $self->root . '/' . $env->{"PATH_INFO"} . $self->dir_index
ABresult
0X0
100
111
52 and -f $self->root . '/' . $env->{PATH_INFO} . $self->dir_index ) {
53  
54 4 $env->{PATH_INFO} .= $self->dir_index();
55 }
56  
57 10 return $self->app->($env);
58 }
59  
60 2 1;
↑ Summary