File Coverage

lib/App/PRT/Collector/AllFiles.pm
Criterion Covered Total %
statement 36 36 100.0
branch 8 8 100.0
condition n/a
subroutine 9 9 100.0
pod 0 4 0.0
total 53 57 92.9


line stmt bran cond sub pod time code
1             package App::PRT::Collector::AllFiles;
2 2     2   2628 use strict;
  2         13  
  2         57  
3 2     2   10 use warnings;
  2         7  
  2         47  
4 2     2   1033 use File::Find::Rule;
  2         16958  
  2         14  
5 2     2   116 use Path::Class;
  2         3  
  2         933  
6              
7             # find project root directory from specified directory path
8             # If exists cpanfile on path, it is a project root.
9             #
10             # returns:
11             # directory path (when found)
12             # undef (when not found)
13             sub find_project_root_directory {
14 7     7 0 19229 my ($class, $directory) = @_;
15              
16 7 100       114 die "$directory does not exist" unless -d $directory;
17              
18 6         32 my $current = dir($directory);
19 6         388 while (1) {
20 11 100       356 if (-e $current->file('cpanfile')) {
21 4         671 return $current->stringify;
22             }
23              
24 7 100       962 if ($current eq $current->parent) {
25             # not found
26 2         214 return;
27             }
28              
29 5         531 $current = $current->parent;
30             }
31             }
32              
33             sub new {
34 5     5 0 13424 my ($class, $directory) = @_;
35              
36 5         29 bless {
37             directory => $directory,
38             }, $class;
39             }
40              
41             sub directory {
42 7     7 0 1547 my ($self) = @_;
43              
44 7         131 $self->{directory};
45             }
46              
47             sub collect {
48 2     2 0 116 my ($self) = @_;
49              
50 2 100       7 die "directory @{[ $self->directory ]} does not exist" unless -d $self->directory;
  1         6  
51              
52 1         4 my @files = $self->_retrieve_all_perl_files;
53              
54 1         10 \@files;
55             }
56              
57             sub _retrieve_all_perl_files {
58 1     1   2 my ($self) = @_;
59              
60 1         3 my @ignore_directories = qw(share fatlib _build .git blib local);
61              
62 1         7 my $rule = File::Find::Rule->new;
63 1         16 $rule = $rule->or($rule->new
64             ->directory
65             ->name(@ignore_directories)
66             ->prune
67             ->discard,
68             $rule->new);
69 1         804 my @files = $rule->file
70             ->name(qr/\.(?:pl|pm|psgi|t)\Z/)
71             ->in($self->directory);
72              
73 1         2031 return @files;
74             }
75              
76             1;