From: Robert 'phaylon' Sedlacek Date: Thu, 10 May 2012 02:39:11 +0000 (+0000) Subject: use reusable I/O utils and better error handling X-Git-Tag: v0.001_001~85 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f3d816a01fcb08ef2fb56e1565a2966bafcb08bf;p=scpubgit%2FSystem-Introspector.git use reusable I/O utils and better error handling --- diff --git a/lib/System/Introspector/ResolvConf.pm b/lib/System/Introspector/ResolvConf.pm index a33bd97..7794d4e 100644 --- a/lib/System/Introspector/ResolvConf.pm +++ b/lib/System/Introspector/ResolvConf.pm @@ -1,6 +1,11 @@ package System::Introspector::ResolvConf; use Moo; +use System::Introspector::Util qw( + handle_from_file + transform_exceptions +); + has resolv_conf_file => ( is => 'ro', default => sub { '/etc/resolv.conf' }, @@ -8,23 +13,22 @@ has resolv_conf_file => ( sub gather { my ($self) = @_; - my $fh = $self->_open_resolv_conf_file; - my @resolv; - while (defined( my $line = <$fh> )) { - chomp $line; - next if $line =~ m{^\s*$} - or $line =~ m{^\s*#}; - push @resolv, [split m{\s+}, $line]; - } - return \@resolv; + return transform_exceptions { + my $fh = $self->_open_resolv_conf_file; + my @resolv; + while (defined( my $line = <$fh> )) { + chomp $line; + next if $line =~ m{^\s*$} + or $line =~ m{^\s*#}; + push @resolv, [split m{\s+}, $line]; + } + return { resolv_conf => \@resolv }; + }; } sub _open_resolv_conf_file { my ($self) = @_; - my $file = $self->resolv_conf_file; - open my $fh, '<', $file - or die "Unable to read $file: $!"; - return $fh; + return handle_from_file $self->resolv_conf_file; } 1;