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