From: Robert 'phaylon' Sedlacek Date: Thu, 10 May 2012 02:11:11 +0000 (+0000) Subject: use reusable I/O utils and better error handling X-Git-Tag: v0.001_001~90 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=07a2389f919913774ecf598ce30527c9007da60c;p=scpubgit%2FSystem-Introspector.git use reusable I/O utils and better error handling --- diff --git a/lib/System/Introspector/Host.pm b/lib/System/Introspector/Host.pm index 680df55..0cc0658 100644 --- a/lib/System/Introspector/Host.pm +++ b/lib/System/Introspector/Host.pm @@ -1,11 +1,20 @@ 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, + }; }; } @@ -25,7 +34,7 @@ sub _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; } @@ -34,9 +43,7 @@ sub _gather_uname_info { 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; }