ResolvConf probe for /etc/resolv.conf info
Robert 'phaylon' Sedlacek [Thu, 3 May 2012 16:19:35 +0000 (16:19 +0000)]
lib/System/Introspector/ResolvConf.pm [new file with mode: 0644]

diff --git a/lib/System/Introspector/ResolvConf.pm b/lib/System/Introspector/ResolvConf.pm
new file mode 100644 (file)
index 0000000..cf9513c
--- /dev/null
@@ -0,0 +1,24 @@
+package System::Introspector::ResolvConf;
+use Moo;
+
+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) = @_;
+    open my $fh, '<', '/etc/resolv.conf'
+        or die "Unable to read /etc/resolv.conf: $!";
+    return $fh;
+}
+
+1;