Commit | Line | Data |
8ce5bf49 |
1 | package System::Introspector::FileHandles; |
2 | use Moo; |
3 | |
4 | sub 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 | |
19 | sub _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 | |
27 | 1; |