package System::Introspector::Hosts;
use Moo;

sub gather {
    my ($self) = @_;
    my $fh = $self->_open_hosts_file;
    my @hosts;
    while (defined( my $line = <$fh> )) {
        chomp $line;
        next if $line =~ m{^\s*$}
             or $line =~ m{^\s*#};
        push @hosts, [split m{\s+}, $line];
    }
    return \@hosts;
}

sub _open_hosts_file {
    my ($self) = @_;
    open my $fh, '<', '/etc/hosts'
        or die "Unable to read /etc/hosts: $!\n";
    return $fh;
}

1;
