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' },
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;