DiskUsage probe tests
[scpubgit/System-Introspector.git] / lib / System / Introspector / FileHandles.pm
CommitLineData
8ce5bf49 1package System::Introspector::FileHandles;
2use Moo;
3
4sub gather {
5 my ($self) = @_;
6 my $pipe = $self->_open_lsof_pipe;
7 my @handles;
8 while (defined( my $line = <$pipe> )) {
9 chomp $line;
10 my @fields = split m{\0}, $line;
11 push @handles, { map {
12 m{^(.)(.*)$};
13 ($1, $2);
14 } @fields };
15 }
16 return \@handles;
17}
18
19sub _open_lsof_pipe {
20 my ($self) = @_;
21 my $command = 'lsof -F0';
22 open my $pipe, '-|', $command
23 or die "Unable to open pipe to '$command': $!\n";
24 return $pipe;
25}
26
271;