| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::PRT::Collector::GitDirectory; | 
| 2 | 2 |  |  | 2 |  | 2251 | use strict; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 78 |  | 
| 3 | 2 |  |  | 2 |  | 11 | use warnings; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 77 |  | 
| 4 | 2 |  |  | 2 |  | 11 | use Path::Class; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 912 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | # find git directory from specified directory path | 
| 7 |  |  |  |  |  |  | # returns: | 
| 8 |  |  |  |  |  |  | #   directory path (when found) | 
| 9 |  |  |  |  |  |  | #   undef          (when not found) | 
| 10 |  |  |  |  |  |  | sub find_git_root_directory { | 
| 11 | 8 |  |  | 8 | 0 | 26818 | my ($class, $directory) = @_; | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 8 | 100 |  |  |  | 296 | die "$directory does not exist" unless -d $directory; | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 7 |  |  |  |  | 74 | my $current = dir($directory); | 
| 16 | 7 |  |  |  |  | 1404 | while (1) { | 
| 17 | 16 | 100 |  |  |  | 1233 | if (-d $current->subdir('.git')) { | 
| 18 | 3 |  |  |  |  | 363 | return $current->stringify; | 
| 19 |  |  |  |  |  |  | } | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 13 | 100 |  |  |  | 2000 | if ($current eq $current->parent) { | 
| 22 |  |  |  |  |  |  | # not found | 
| 23 | 4 |  |  |  |  | 519 | return; | 
| 24 |  |  |  |  |  |  | } | 
| 25 | 9 |  |  |  |  | 1721 | $current = $current->parent; | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  | } | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | sub new { | 
| 30 | 6 |  |  | 6 | 0 | 162073 | my ($class, $directory) = @_; | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 6 | 100 |  |  |  | 72 | die 'directory requird' unless defined $directory; | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 5 | 100 |  |  |  | 1004 | die "directory $directory does not exist" unless -d $directory; | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 4 |  |  |  |  | 147 | bless { | 
| 37 |  |  |  |  |  |  | directory     => $directory, | 
| 38 |  |  |  |  |  |  | }, $class; | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | sub collect { | 
| 42 | 3 |  |  | 3 | 0 | 116 | my ($self) = @_; | 
| 43 | 3 |  |  |  |  | 306 | my $git_directory = dir($self->directory)->subdir('.git'); | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 3 |  |  |  |  | 1751 | my $output = `git --no-pager --git-dir $git_directory ls-files --full-name 2> /dev/null`; | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 3 | 100 |  |  |  | 37625 | if ($?) { | 
| 48 |  |  |  |  |  |  | # when success, exit status is 0 | 
| 49 | 1 |  |  |  |  | 22 | die "directory @{[ $self->directory ]} seems not a git repository"; | 
|  | 1 |  |  |  |  | 22 |  | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 2 |  |  |  |  | 287 | my $dir = dir($self->directory); | 
| 53 | 2 |  |  |  |  | 699 | [ map { $dir->file($_)->stringify } split /\n/, $output ]; | 
|  | 7 |  |  |  |  | 1156 |  | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | sub directory { | 
| 57 | 8 |  |  | 8 | 0 | 1990 | my ($self) = @_; | 
| 58 |  |  |  |  |  |  |  | 
| 59 | 8 |  |  |  |  | 282 | $self->{directory}; | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | 1; |