| 1 | # App::GitFind::Searcher::Git - Search for files in a Git index | ||||||||||||||||||||||||||||||||||||||||||
| 2 | package App::GitFind::Searcher::Git; | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use App::GitFind::Base; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our $VERSION = '0.000002'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use parent 'App::GitFind::Searcher'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Class::Tiny qw(repo searchbase), | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | { | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | scan_submodules => sub { true }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use App::GitFind::Entry::GitIndex; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Git::Raw; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Git::Raw::Submodule; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | # Docs {{{1 | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | App::GitFind::Searcher::Git - Search for files on disk | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | This is an L<App::GitFind::Searcher> that looks through a file system. | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | # }}}1 | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | =head2 run | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | Conducts a search. | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my ($self, $callback) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | return $self->_run($callback, $self->repo); | |||||||||||||||||||||||||||||||||||||||||
| 46 | } #run() | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | # Implementation of run(). Call as $self->_run($callback, $repo). | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub _run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my ($self, $callback, $repo) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my $index = $repo->index; | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my %submodules; # map submodule paths to Git::Raw::Submodule instances | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if($self->scan_submodules) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | # Does $repo have submodules? (EXPERIMENTAL) | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my @submodule_names; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | Git::Raw::Submodule->foreach($repo, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | push @submodule_names, $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | return 0; # Tell foreach() to keep going | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | vlog { "Submodules:", join ', ', @submodule_names } if @submodule_names; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | # Open the submodules | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | for(@submodule_names) { | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my $sm = Git::Raw::Submodule->lookup($repo, $_); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | unless($sm) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | vwarn { "Could not access submodule $_" }; # TODO die? | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $submodules{$_} = $sm; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | for my $idxe ($index->entries) { | |||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $entry = App::GitFind::Entry::GitIndex->new(-obj=>$idxe, | |||||||||||||||||||||||||||||||||||||||||
| 77 | -repo=>$repo, -searchbase=>$self->searchbase); | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $callback->($entry); | |||||||||||||||||||||||||||||||||||||||||
| 79 | # TODO prune and other control | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if(my $sm = $submodules{$idxe->path}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | vlog { "Entering submodule", $sm->name } 2; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $smrepo = $sm->open; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | die "Could not open repo for submodule @{[$smrepo->name]}: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $self->_run($callback, $smrepo); | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | vlog { "Exiting submodule", $sm->name } 2; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | # Make sure everything is closed | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | undef $smrepo; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | undef $sm; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | undef $submodules{$idxe->path}; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | undef $entry; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | } #_run() | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | =head2 BUILD | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my ($self, $hrArgs) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | unless($self->searchbase && $self->repo && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->searchbase and $self->repo and $self->repo->DOES("Git::Raw::Repository")
$self->searchbase and $self->repo
MC/DC0%0/3
$self->searchbase and $self->repo and $self->repo->DOES("Git::Raw::Repository")
$self->searchbase
$self->repo
$self->repo->DOES("Git::Raw::Repository")
Truth table0%0/4
A and B and C
A= $self->searchbaseB= $self->repoC= $self->repo->DOES("Git::Raw::Repository")
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | $self->repo->DOES('Git::Raw::Repository')) { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | require Carp; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | Carp::croak 'Need a -searchbase' unless $self->searchbase; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | Carp::croak 'Need a -repo' unless $self->repo; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | Carp::croak 'Repo must be a Git::Raw::Repository' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | unless $self->repo->DOES('Git::Raw::Repository'); | ||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | } #BUILD() | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 115 | __END__ | ||||||||||||||||||||||||||||||||||||||||||