sub gather {
my ($self) = @_;
log_debug { "Gathering Perl library information" };
-
-if (0) {
- log_warn { "simulating hang" };
-
- while(1) {
- sleep(1)
- };
-}
-
+
return transform_exceptions {
my $pipe = $self->_open_locate_libdirs_pipe;
my %libdir;
while (defined( my $line = <$pipe> )) {
chomp $line;
+
$libdir{ $line } = transform_exceptions {
return { modules => $self->_gather_libdir_info($line) };
};
}
- log_trace { "Completed gathering Perl library information" };
+ log_trace { "Completed gathering Perl library information" };
return { libdirs_perl => \%libdir };
};
}
sub _gather_libdir_info {
my ($self, $libdir) = @_;
my %modules;
+ my $packlistfh;
log_debug { "Gathering Perl libdir info for '$libdir'" };
+
+ $packlistfh = $self->_open_find_packlist_pipe($libdir);
+
+ while(<$packlistfh>) {
+ chomp(my $file = $_);
+ my $module_name = $self->_module_name_from_packlist_path($file, $libdir);
+
+ unless(defined($module_name)) {
+ log_error { "Could not figure out module information for packlist file '$file'" };
+ next;
+ }
- my $installed = ExtUtils::Installed->new(inc_override => [ $libdir ]);
-
- foreach my $module ($installed->modules) {
- my $packlist = $installed->packlist($module)->packlist_file;
+ $modules{$module_name} = {};
- Dlog_trace { "Packlist file for '$module' in '$libdir' is '$_'" } $packlist;
-
- $modules{$module} = {};
+ if ($self->enumerate_packlists) {
+ my $packlist = output_from_file($file);
+ my @files = split("\n", $packlist);
-if (0) {
- log_warn { "Simulating slowness" };
- for(1 .. 20) { sleep(1) }
+ $modules{$module_name}->{packlist} = \@files;
+ }
+ }
+
+ return \%modules;
}
-
- if ($self->enumerate_packlists && -f $packlist) {
- $modules{$module}->{packlist} = [ $installed->files($module, 'all') ];
- }
- }
- return \%modules;
+sub _open_find_packlist_pipe {
+ my ($self, $dir) = @_;
+ log_debug { "Executing 'find' to search for Perl module packlists in '$dir'" };
+ return handle_from_command
+ sprintf q{find %s -type f -name '.packlist'}, $dir;
+}
+
+sub _module_name_from_packlist_path {
+ my ($self, $path, $root) = @_;
+ my $module_name = $path;
+
+ unless($module_name =~ s/^$root//) {
+ log_debug { "Regex failure with '$path': was it rooted in '$root' ?" };
+ return undef;
+ }
+
+ unless($module_name =~ s/\.packlist$//) {
+ log_debug { "Could not remove packlist file name from '$path'" };
+ return undef;
+ }
+
+ $module_name =~ s,/,::,g;
+
+ unless($module_name =~ s/^.+?auto:://) {
+ log_debug { "Did not find 'auto' prefix in packlist path for '$path'" };
+ return undef;
+ }
+
+ $module_name =~ s/::$//;
+
+ return $module_name;
}
+
+sub _open_locate_libdirs_pipe {
+ my ($self) = @_;
+ my $root = $self->root;
+ $root .= '/'
+ unless $root =~ m{/$};
+ log_debug { "Executing 'locate' to identify Perl 5 library directories under '$root'" };
+ my $command = sprintf q{locate --regex '^%s.*lib/perl5$'}, $root;
+ return handle_from_command $command;
+}
+
+# The following are methods for the original larger report style.
+# They are archived here so they can be reintroduced as a
+# set of data that is collected according to attributes on this
+# this class.
+
#sub _enumerate_metadata {
# my ($self, $libdir, $module) = @_;
#
# sprintf q{find %s -name '.packlist'}, $libdir;
#}
-sub _open_locate_libdirs_pipe {
- my ($self) = @_;
- my $root = $self->root;
- $root .= '/'
- unless $root =~ m{/$};
- log_debug { "Executing 'locate' to identify Perl 5 library directories" };
- return handle_from_command sprintf
- #lib/perl5 for Local::Lib and debian installed perl? - lib/perl for others?
- q{locate --regex '^%s.*lib/perl$'}, $root;
-# q{locate --regex '^%s.*lib/perl5$'}, $root;
-}
-
1;
__END__
my $probe = System::Introspector::Probe::LibDirs::Perl->new(
root => $dir,
);
-my $data = $probe->gather;
-
-my $sha = delete $data
- ->{libdirs_perl}{"$dir/lib/perl5"}{modules}{Foo}[0]{sha256_hex};
-ok $sha, 'contains SHA fingerprint';
-my $size = delete $data
- ->{libdirs_perl}{"$dir/lib/perl5"}{modules}{Foo}[0]{size};
-ok $size, 'contains file size';
+my $data = $probe->gather;
is_deeply $data, {
libdirs_perl => {
"$dir/lib/perl5" => {
modules => {
- Foo => [
- { file => "$dir/lib/perl5/Foo.pm", version => 0.001 },
- ],
+ Foo => {
+ packlist => [qw( t/data/libdir/perl/lib/perl5/Foo t/data/libdir/perl/lib/perl5/Foo/Bar.pm )],
+ }, 'Foo::Biddle' => {
+ packlist => [qw( t/data/libdir/perl/lib/perl5/Foo/Bar/Biddle.pm t/data/libdir/perl/lib/perl5/Foo/Bar/Biddle/Bloke.pm )],
+ }
},
},
},
-}, 'package found';
+}, 'Report data matches template';
done_testing;