| 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
| |||||||||||
| 14 | |||||||||||
| 15 | 7 | my $current = dir($directory); | |||||||||
| 16 | 7 | while (1) { | |||||||||
| 17 | 16 | ▶ | if (-d $current->subdir('.git')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 3 | return $current->stringify; | |||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | 13 | ▶ | if ($current eq $current->parent) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 33 | |||||||||||
| 34 | 5 | ▶ | die "directory $directory does not exist" unless -d $directory; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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; | |||||||||