File Coverage

blib/lib/Test/DirectoryLayout.pm
Criterion Covered Total %
statement 35 35 100.0
branch 8 10 80.0
condition n/a
subroutine 7 7 100.0
pod 3 3 100.0
total 53 55 96.3


line stmt bran cond sub pod time code
1             package Test::DirectoryLayout;
2             $Test::DirectoryLayout::VERSION = '0.001';
3              
4             #ABSTRACT: Test directory layout for standard compliance
5              
6 1     1   70479 use strict;
  1         13  
  1         30  
7 1     1   5 use warnings;
  1         3  
  1         28  
8              
9 1     1   6 use base qw(Test::Builder::Module);
  1         1  
  1         557  
10             our @EXPORT = qw(directory_layout_ok get_allowed_dirs set_allowed_dirs);
11              
12             my @diags;
13             my $CLASS = __PACKAGE__;
14             my $Tester = $CLASS->builder;
15              
16             {
17             my @allowed_dirs = qw(bin blib lib config doc t);
18              
19             sub get_allowed_dirs {
20 6     6 1 9365 return \@allowed_dirs;
21             }
22              
23             sub set_allowed_dirs {
24 2     2 1 733 my ($dirs) = @_;
25 2         10 @allowed_dirs = @$dirs;
26             }
27             }
28              
29             sub directory_layout_ok {
30 3     3 1 21477 my ($dir) = @_;
31 3 50       11 $dir = '.' unless $dir;
32              
33             # clean up diagnostics from prior tests
34 3         8 undef @diags;
35              
36 3         4 my $description = 'directory layout';
37 3         8 my $directories_ok = _directories_ok($dir);
38              
39 3         30 $Tester->ok( $directories_ok, $description );
40 3 100       1367 unless ($directories_ok) {
41 1         4 unshift @diags, "Found the following problems:";
42 1         11 $Tester->diag( join( "\n ", @diags ) );
43             }
44              
45 3         162 return $directories_ok;
46             }
47              
48             sub _directories_ok {
49 3     3   7 my ($dir) = @_;
50              
51 3         4 my $ok = 1;
52 3         7 my $allowed_dirs = get_allowed_dirs;
53              
54 3 50       106 opendir( my $dh, $dir ) || die "Can't opendir $dir: $!";
55 3 100       65 my @dirs = grep { !/^\./ && -d "$dir/$_" } readdir($dh);
  20         231  
56 3         36 closedir $dh;
57 3         10 for my $dir (@dirs) {
58 14         163 my $allowed = grep ( /^$dir$/, @$allowed_dirs );
59 14 100       37 unless ($allowed) {
60 1         13 $ok = 0;
61 1         5 push @diags, qq{Directory '$dir' is not allowed};
62             }
63             }
64 3         13 return $ok;
65             }
66              
67             1;
68              
69             __END__