PRT/Collector/GitDirectory.pm

filter: Statementstmt 100% 34 / 34 Branchbran 100% 12 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 4 totaltotal 92.9% 53 / 57 CC 7 SCAR 9.3
CC
7
Cov
100%
find_git_root_directory
4.0
new
3.0
collect
2.0
CRAP 2.5
« PRT/Command/RenameNameSpace.pm ↑ Summary PRT/CLI.pm »
1 package App::PRT::Collector::GitDirectory;
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 Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # find git directory from specified directory path
7 # returns:
8 # directory path (when found)
9 # undef (when not found)
10 8 ▶sub find_git_root_directory {
Subroutine find_git_root_directory: called CC=4 SCAR=13.9
Pod undocumented
11 8 my ($class, $directory) = @_;
12  
13 8 ▶ die "$directory does not exist" unless -d $directory;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $directory 1 7 8
14  
15 7 my $current = dir($directory);
16 7 while (1) {
17 16 ▶ if (-d $current->subdir('.git')) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $current->subdir(".git")) 3 13 16
18 3 return $current->stringify;
19 }
20  
21 13 ▶ if ($current eq $current->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current eq $current->parent) 4 9 13
22 # not found
23 4 return;
24 }
25 9 $current = $current->parent;
26 }
27 }
28  
29 6 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod undocumented
30 6 my ($class, $directory) = @_;
31  
32 6 ▶ die 'directory requird' unless defined $directory;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $directory 1 5 6
33  
34 5 ▶ die "directory $directory does not exist" unless -d $directory;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $directory 1 4 5
35  
36 4 bless {
37 directory => $directory,
38 }, $class;
39 }
40  
41 3 ▶sub collect {
Subroutine collect: called CC=2 SCAR=6.9
Pod undocumented
42 3 my ($self) = @_;
43 3 my $git_directory = dir($self->directory)->subdir('.git');
44  
45 3 my $output = `git --no-pager --git-dir $git_directory ls-files --full-name 2> /dev/null`;
46  
47 3 ▶ if ($?) {
Branch: 1 branch
BranchTrueFalseTotal
if ($?) 1 2 3
48 # when success, exit status is 0
49 1 die "directory @{[ $self->directory ]} seems not a git repository";
50 }
51  
52 2 my $dir = dir($self->directory);
53 2 [ map { $dir->file($_)->stringify } split /\n/, $output ];
54 }
55  
56 8 ▶sub directory {
Subroutine directory: called CC=1 SCAR=0.0
Pod undocumented
57 8 my ($self) = @_;
58  
59 8 $self->{directory};
60 }
61  
62 3 1;
« PRT/Command/RenameNameSpace.pm ↑ Summary PRT/CLI.pm »