package System::Introspector::ResolvConf;
use Moo;

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

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

1;
