removed unnecessary 'file' structure level from Apt packages probe
[scpubgit/System-Introspector.git] / lib / System / Introspector / Probe / FileHandles.pm
CommitLineData
afd7c030 1package System::Introspector::Probe::FileHandles;
8ce5bf49 2use Moo;
3
f1820b4e 4use System::Introspector::Util qw(
5 handle_from_command
6 transform_exceptions
7);
8
9c3e454c 9has lsof_command => (is => 'ro', default => sub { 'lsof' });
10
8ce5bf49 11sub gather {
12 my ($self) = @_;
f1820b4e 13 return transform_exceptions {
14 my $pipe = $self->_open_lsof_pipe;
15 my @handles;
16 while (defined( my $line = <$pipe> )) {
17 chomp $line;
18 my @fields = split m{\0}, $line;
19 push @handles, { map {
20 m{^(.)(.*)$};
21 ($1, $2);
22 } @fields };
23 }
24 return { handles => \@handles };
25 };
8ce5bf49 26}
27
28sub _open_lsof_pipe {
29 my ($self) = @_;
9c3e454c 30 my $lsof = $self->lsof_command;
31 return handle_from_command "$lsof -F0";
8ce5bf49 32}
33
341;
535e84b6 35
36__END__
37
38=head1 NAME
39
40System::Introspector::FileHandles - Gather opened filehandles
41
42=head1 DESCRIPTION
43
44Uses C<lsof> to build a list of open filehandles.
45
46=head1 SEE ALSO
47
48=over
49
50=item L<System::Introspector>
51
52=back
53
54=cut
55