| 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
| |||||||||||||||||||||||||||||
| 45 | 4 | ▶ | $self->dir_index('index.html') unless $self->dir_index; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$env->{"PATH_INFO"} =~ m[/$] and -f $self->root . '/' . $env->{"PATH_INFO"} . $self->dir_index
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
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||