From: Robert 'phaylon' Sedlacek Date: Wed, 9 May 2012 22:17:25 +0000 (+0000) Subject: use command pipe output and exception handling utils, handles now under 'handles... X-Git-Tag: v0.001_001~100 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f1820b4efcfd01315849c43c313ba6e039ebb7a4;p=scpubgit%2FSystem-Introspector.git use command pipe output and exception handling utils, handles now under 'handles' key to discern from 'error' --- diff --git a/lib/System/Introspector/FileHandles.pm b/lib/System/Introspector/FileHandles.pm index b185948..e729ff5 100644 --- a/lib/System/Introspector/FileHandles.pm +++ b/lib/System/Introspector/FileHandles.pm @@ -1,27 +1,31 @@ package System::Introspector::FileHandles; use Moo; +use System::Introspector::Util qw( + handle_from_command + transform_exceptions +); + sub gather { my ($self) = @_; - my $pipe = $self->_open_lsof_pipe; - my @handles; - while (defined( my $line = <$pipe> )) { - chomp $line; - my @fields = split m{\0}, $line; - push @handles, { map { - m{^(.)(.*)$}; - ($1, $2); - } @fields }; - } - return \@handles; + return transform_exceptions { + my $pipe = $self->_open_lsof_pipe; + my @handles; + while (defined( my $line = <$pipe> )) { + chomp $line; + my @fields = split m{\0}, $line; + push @handles, { map { + m{^(.)(.*)$}; + ($1, $2); + } @fields }; + } + return { handles => \@handles }; + }; } sub _open_lsof_pipe { my ($self) = @_; - my $command = 'lsof -F0'; - open my $pipe, '-|', $command - or die "Unable to open pipe to '$command': $!\n"; - return $pipe; + return handle_from_command 'lsof -F0'; } 1;