Commit | Line | Data |
---|---|---|
645a8f49 | 1 | package System::Introspector::Hosts; |
2 | use Moo; | |
3 | ||
4 | sub gather { | |
5 | my ($self) = @_; | |
6 | my $fh = $self->_open_hosts_file; | |
7 | my @hosts; | |
8 | while (defined( my $line = <$fh> )) { | |
9 | chomp $line; | |
10 | next if $line =~ m{^\s*$} | |
11 | or $line =~ m{^\s*#}; | |
12 | push @hosts, [split m{\s+}, $line]; | |
13 | } | |
14 | return \@hosts; | |
15 | } | |
16 | ||
17 | sub _open_hosts_file { | |
18 | my ($self) = @_; | |
19 | open my $fh, '<', '/etc/hosts' | |
20 | or die "Unable to read /etc/hosts: $!\n"; | |
21 | return $fh; | |
22 | } | |
23 | ||
24 | 1; |