package System::Introspector::Host;
use Moo;
+use System::Introspector::Util qw(
+ handle_from_command
+ output_from_command
+ output_from_file
+ transform_exceptions
+);
+
sub gather {
my ($self) = @_;
- return {
- hostname => $self->_gather_hostname,
- uname => $self->_gather_uname_info,
+ return transform_exceptions {
+ return {
+ hostname => $self->_gather_hostname,
+ uname => $self->_gather_uname_info,
+ };
};
}
my %uname;
for my $field (@UnameFields) {
(my $option = $field) =~ s{_}{-}g;
- my $value = `uname --$option`;
+ my $value = output_from_command [uname => "--$option"];
chomp $value;
$uname{ $field } = $value;
}
sub _gather_hostname {
my ($self) = @_;
- open my $fh, '<', '/etc/hostname'
- or die "Unable to read /etc/hostname: $!\n";
- my $hostname = <$fh>;
+ my $hostname = output_from_file '/etc/hostname';
chomp $hostname;
return $hostname;
}