Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / Module / Install / Admin / Find.pm
1 package Module::Install::Admin::Find;
2
3 use strict;
4 use File::Find ();
5 use Module::Install::Base ();
6 use vars qw{$VERSION @ISA};
7 BEGIN {
8         $VERSION = '0.91';;
9         @ISA = qw(Module::Install::Base);
10 }
11
12 sub find_extensions {
13     my $self = shift;
14     $self->_top->find_extensions(@_);
15 }
16
17 sub find_in_inc {
18     my ($self, $pkg) = @_;
19
20     unless ($pkg =~ /\.pm$/) {
21         $pkg =~ s!::!/!g;
22         $pkg = "$pkg.pm";
23     }
24
25     my @found;
26     foreach my $inc (@INC) {
27         next if $inc eq $self->_top->{prefix} or ref($inc);
28         push @found, "$inc/$pkg" if -f "$inc/$pkg";
29     }
30
31     wantarray ? @found : $found[0];
32 }
33
34 sub glob_in_inc {
35     my ($self, $pkg) = @_;
36
37     unless ($pkg =~ /\.pm$/) {
38         $pkg =~ s!::!/!g;
39         $pkg = "$pkg.pm";
40     }
41
42     my @found;
43     foreach my $inc (@INC) {
44         next if $inc eq $self->_top->{prefix} or ref($inc);
45         push @found, [ do {
46             my $p = $_;
47             $p =~ s!^\Q$inc\E/!!;
48             $p =~ s!/!::!g;
49             $p =~ s!\.pm\Z!!gi;
50             $p
51         }, $_ ] for grep -e, glob("$inc/$pkg");
52     }
53
54     wantarray ? @found : $found[0];
55 }
56
57 sub find_files {
58     my ($self, $file, $path) = @_;
59     $path = '' if not defined $path;
60     $file = "$path/$file" if length($path);
61     if (-f $file) {
62         return ($file);
63     }
64     elsif (-d $file) {
65         my @files = ();
66         local *DIR;
67         opendir(DIR, $file) or die "Can't opendir $file";
68         while (my $new_file = readdir(DIR)) {
69             next if $new_file =~ /^(\.|\.\.)$/;
70             push @files, $self->find_files($new_file, $file);
71         }
72         return @files;
73     }
74     return ();
75 }
76
77 1;