Commit | Line | Data |
afd7c030 |
1 | package System::Introspector::Probe::FileHandles; |
8ce5bf49 |
2 | use Moo; |
3 | |
f1820b4e |
4 | use System::Introspector::Util qw( |
5 | handle_from_command |
6 | transform_exceptions |
7 | ); |
8 | |
9c3e454c |
9 | has lsof_command => (is => 'ro', default => sub { 'lsof' }); |
10 | |
8ce5bf49 |
11 | sub 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 | |
28 | sub _open_lsof_pipe { |
29 | my ($self) = @_; |
9c3e454c |
30 | my $lsof = $self->lsof_command; |
31 | return handle_from_command "$lsof -F0"; |
8ce5bf49 |
32 | } |
33 | |
34 | 1; |
535e84b6 |
35 | |
36 | __END__ |
37 | |
38 | =head1 NAME |
39 | |
40 | System::Introspector::FileHandles - Gather opened filehandles |
41 | |
42 | =head1 DESCRIPTION |
43 | |
44 | Uses 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 | |