From: Robert 'phaylon' Sedlacek Date: Thu, 10 May 2012 18:19:33 +0000 (+0000) Subject: use reusable I/O utils, more solid error handling X-Git-Tag: v0.001_001~83 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=579b73f08028e8ab33ccc2f02ad7db8e7d9ff167;p=scpubgit%2FSystem-Introspector.git use reusable I/O utils, more solid error handling --- diff --git a/lib/System/Introspector/MountPoints.pm b/lib/System/Introspector/MountPoints.pm index f6fdf15..f6ad0e4 100644 --- a/lib/System/Introspector/MountPoints.pm +++ b/lib/System/Introspector/MountPoints.pm @@ -1,19 +1,28 @@ package System::Introspector::MountPoints; use Moo; +use System::Introspector::Util qw( + handle_from_file + transform_exceptions +); + sub gather { my ($self) = @_; return { - mtab => $self->_parse_tab_fh($self->_open_fh('/etc/mtab')), - fstab => $self->_parse_tab_fh($self->_open_fh('/etc/fstab')), + mtab => transform_exceptions { + return { entries + => $self->_parse_tab_fh($self->_open_fh('/etc/mtab')) }; + }, + fstab => transform_exceptions { + return { entries + => $self->_parse_tab_fh($self->_open_fh('/etc/fstab')) }; + }, }; } sub _open_fh { my ($self, $file) = @_; - open my $fh, '<', $file - or die "Unable to open $file: $!\n"; - return $fh; + return handle_from_file $file; } sub _parse_tab_fh { diff --git a/t/mountpoints.t b/t/mountpoints.t index 4f3428e..8f8e5b7 100644 --- a/t/mountpoints.t +++ b/t/mountpoints.t @@ -22,7 +22,8 @@ my $run_test = sub { my $tab = shift; return sub { for my $field (@fields) { - ok not(grep { not defined $_->{$field} } @$tab), + my @entries = @{ $tab->{entries} }; + ok not(grep { not defined $_->{$field} } @entries), "all have $field"; } };