From: Robert 'phaylon' Sedlacek Date: Thu, 3 May 2012 16:13:23 +0000 (+0000) Subject: Hosts probe for /etc/hosts info X-Git-Tag: v0.001_001~132 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=645a8f49dc7a995c820230140182ce27ef20da59;p=scpubgit%2FSystem-Introspector.git Hosts probe for /etc/hosts info --- diff --git a/lib/System/Introspector/Hosts.pm b/lib/System/Introspector/Hosts.pm new file mode 100644 index 0000000..d5e880c --- /dev/null +++ b/lib/System/Introspector/Hosts.pm @@ -0,0 +1,24 @@ +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;