PRT/Collector/AllFiles.pm

filter: Statementstmt 100% 37 / 37 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 93.1% 54 / 58 CC 5 SCAR 7.3
CC
5
Cov
100%
find_project_root_directory
4.0
collect
2.0
BEGIN
1.0
CRAP 2.1
« PRT/Command/IntroduceVariables.pm ↑ Summary PRT/Util/DestinationFile.pm »
1 package App::PRT::Collector::AllFiles;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use File::Find::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 7 ▶sub find_project_root_directory {
Subroutine find_project_root_directory: called CC=4 SCAR=13.9
Pod undocumented
14 7 my ($class, $directory) = @_;
15  
16 7 ▶ die "$directory does not exist" unless -d $directory;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $directory 1 6 7
17  
18 6 my $current = dir($directory);
19 6 while (1) {
20 11 ▶ if (-e $current->file('cpanfile')) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $current->file("cpanfile")) 4 7 11
21 4 return $current->stringify;
22 }
23  
24 7 ▶ if ($current eq $current->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current eq $current->parent) 2 5 7
25 # not found
26 2 return;
27 }
28  
29 5 $current = $current->parent;
30 }
31 }
32  
33 5 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
34 5 my ($class, $directory) = @_;
35  
36 5 bless {
37 directory => $directory,
38 }, $class;
39 }
40  
41 7 ▶sub directory {
Subroutine directory: called CC=1 SCAR=0.0
Pod undocumented
42 7 my ($self) = @_;
43  
44 7 $self->{directory};
45 }
46  
47 2 ▶sub collect {
Subroutine collect: called CC=2 SCAR=6.9
Pod undocumented
48 2 my ($self) = @_;
49  
50 2 ▶ die "directory @{[ $self->directory ]} does not exist" unless -d $self->directory;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $self->directory 1 1 2
51  
52 1 my @files = $self->_retrieve_all_perl_files;
53  
54 1 \@files;
55 }
56  
57 1 ▶sub _retrieve_all_perl_files {
Subroutine _retrieve_all_perl_files: called CC=1 SCAR=0.0
58 1 my ($self) = @_;
59  
60 1 my @ignore_directories = qw(share fatlib _build .git blib local);
61  
62 1 my $rule = File::Find::Rule->new;
63 1 $rule = $rule->or($rule->new
64 ->directory
65 ->name(@ignore_directories)
66 ->prune
67 ->discard,
68 $rule->new);
69 1 my @files = $rule->file
70 ->name(qr/\.(?:pl|pm|psgi|t)\Z/)
71 ->in($self->directory);
72  
73 1 return @files;
74 }
75  
76 3 1;
« PRT/Command/IntroduceVariables.pm ↑ Summary PRT/Util/DestinationFile.pm »