test for processes key in result
[scpubgit/System-Introspector.git] / lib / System / Introspector / Util.pm
CommitLineData
f79a227c 1use strictures 1;
2
3package System::Introspector::Util;
4use Exporter 'import';
5
6our @EXPORT_OK = qw(
7 handle_from_command
8 transform_exceptions
9);
10
11sub transform_exceptions (&) {
12 my ($code) = @_;
13 local $@;
14 my $result = eval { $code->() };
15 return { error => "$@" }
16 if $@;
17 return $result;
18}
19
20sub handle_from_command {
21 my ($command) = @_;
22 open my $pipe, '-|', $command
23 or die "Unable to read from command '$command': $!\n";
24 return $pipe;
25}
26
271;