documentation and attribution fixes
[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     lines_from_command
6     transform_exceptions
7 );
8
9 has lsof_command => (is => 'ro', default => sub { 'lsof' });
10
11 sub gather {
12     my ($self) = @_;
13     return transform_exceptions {
14         my @lines = lines_from_command [$self->_lsof_command_call];
15         my @handles;
16         for my $line (@lines) {
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     };
26 }
27
28 sub _lsof_command_call {
29     my ($self) = @_;
30     return $self->lsof_command, '-F0';
31 }
32
33 1;
34
35 __END__
36
37 =head1 NAME
38
39 System::Introspector::Probe::FileHandles - Gather opened filehandles
40
41 =head1 DESCRIPTION
42
43 Uses C<lsof> to build a list of open filehandles.
44
45 =head1 SEE ALSO
46
47 =over
48
49 =item L<System::Introspector>
50
51 =back
52
53 =head1 COPYRIGHT
54
55 Copyright (c) 2012 the L<System::Introspector>
56 L<AUTHOR|System::Introspector/AUTHOR>,
57 L<CONTRIBUTORS|System::Introspector/CONTRIBUTORS> and
58 L<SPONSORS|System::Introspector/SPONSORS>.
59
60 =head1 LICENSE
61
62 This library is free software and may be distributed under the same terms
63 as perl itself.
64
65 =cut