use Module::Metadata;
use Digest::SHA;
+use System::Introspector::Util qw(
+ handle_from_command
+ transform_exceptions
+);
+
has root => (
is => 'ro',
default => sub { '/' },
sub gather {
my ($self) = @_;
- my $pipe = $self->_open_locate_libdirs_pipe;
- my %libdir;
- while (defined( my $line = <$pipe> )) {
- chomp $line;
- $libdir{ $line } = $self->_gather_libdir_info($line);
- }
- return \%libdir;
+ 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) };
+ };
+ }
+ return { libdirs_perl => \%libdir };
+ };
}
sub _gather_libdir_info {
sub _open_locate_pm_pipe {
my ($self, $libdir) = @_;
- my $command = sprintf
- q{find %s -name '*.pm'},
- $libdir;
- open my $pipe, '-|', $command
- or die "Unable to open pipe to '$command': $!\n";
- return $pipe;
+ return handle_from_command
+ sprintf q{find %s -name '*.pm'}, $libdir;
}
sub _open_locate_libdirs_pipe {
my $root = $self->root;
$root .= '/'
unless $root =~ m{/$};
- my $command = sprintf
- q{locate --regex '^%s.*lib/perl5$'},
- $root;
- open my $pipe, '-|', $command
- or die "Unable to open pipe to '$command': $!\n";
- return $pipe;
+ return handle_from_command sprintf
+ q{locate --regex '^%s.*lib/perl5$'}, $root;
}
1;
);
my $data = $probe->gather;
-my $sha = delete $data->{"$dir/lib/perl5"}{Foo}[0]{sha256_hex};
+my $sha = delete $data
+ ->{libdirs_perl}{"$dir/lib/perl5"}{modules}{Foo}[0]{sha256_hex};
ok $sha, 'contains SHA fingerprint';
-my $size = delete $data->{"$dir/lib/perl5"}{Foo}[0]{size};
+my $size = delete $data
+ ->{libdirs_perl}{"$dir/lib/perl5"}{modules}{Foo}[0]{size};
ok $size, 'contains file size';
is_deeply $data, {
- "$dir/lib/perl5" => {
- Foo => [
- { file => "$dir/lib/perl5/Foo.pm", version => 0.001 },
- ],
+ libdirs_perl => {
+ "$dir/lib/perl5" => {
+ modules => {
+ Foo => [
+ { file => "$dir/lib/perl5/Foo.pm", version => 0.001 },
+ ],
+ },
+ },
},
}, 'package found';