package System::Introspector::FileHandles;
use Moo;
+use System::Introspector::Util qw(
+ handle_from_command
+ transform_exceptions
+);
+
sub gather {
my ($self) = @_;
- my $pipe = $self->_open_lsof_pipe;
- my @handles;
- while (defined( my $line = <$pipe> )) {
- chomp $line;
- my @fields = split m{\0}, $line;
- push @handles, { map {
- m{^(.)(.*)$};
- ($1, $2);
- } @fields };
- }
- return \@handles;
+ return transform_exceptions {
+ my $pipe = $self->_open_lsof_pipe;
+ my @handles;
+ while (defined( my $line = <$pipe> )) {
+ chomp $line;
+ my @fields = split m{\0}, $line;
+ push @handles, { map {
+ m{^(.)(.*)$};
+ ($1, $2);
+ } @fields };
+ }
+ return { handles => \@handles };
+ };
}
sub _open_lsof_pipe {
my ($self) = @_;
- my $command = 'lsof -F0';
- open my $pipe, '-|', $command
- or die "Unable to open pipe to '$command': $!\n";
- return $pipe;
+ return handle_from_command 'lsof -F0';
}
1;