use strictures 1;

package System::Introspector::Util;
use Exporter 'import';

our @EXPORT_OK = qw(
    handle_from_command
    transform_exceptions
);

sub transform_exceptions (&) {
    my ($code) = @_;
    local $@;
    my $result = eval { $code->() };
    return { error => "$@" }
        if $@;
    return $result;
}

sub handle_from_command {
    my ($command) = @_;
    open my $pipe, '-|', $command
        or die "Unable to read from command '$command': $!\n";
    return $pipe;
}

1;
