simplified ResolvConf probe output and make it conform to standard file data structure
Robert 'phaylon' Sedlacek [Tue, 19 Jun 2012 21:56:39 +0000 (21:56 +0000)]
lib/System/Introspector/Probe/ResolvConf.pm
t/resolvconf.t

index 3417496..753085f 100644 (file)
@@ -2,7 +2,7 @@ package System::Introspector::Probe::ResolvConf;
 use Moo;
 
 use System::Introspector::Util qw(
-    handle_from_file
+    output_from_file
     transform_exceptions
 );
 
@@ -13,24 +13,17 @@ has resolv_conf_file => (
 
 sub gather {
     my ($self) = @_;
-    return transform_exceptions {
-        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_conf => \@resolv };
+    return {
+        resolv_conf_file => transform_exceptions {
+            my $file = $self->resolv_conf_file;
+            return {
+                file_name => $file,
+                body => scalar output_from_file $file,
+            };
+        },
     };
 }
 
-sub _open_resolv_conf_file {
-    my ($self) = @_;
-    return handle_from_file $self->resolv_conf_file;
-}
-
 1;
 
 __END__
index 1341e33..9d2d773 100644 (file)
@@ -9,14 +9,16 @@ my $probe = System::Introspector::Probe::ResolvConf->new(
 );
 my $result = $probe->gather;
 ok $result, 'received data';
-my $data = $result->{resolv_conf};
+my $data = $result->{resolv_conf_file};
 ok $data, 'received resolv.conf data';
 
-is_deeply $data,
-    [[qw( domain foo )],
-     [qw( search bar )],
-     [qw( nameserver baz )],
-     [qw( nameserver qux )]],
-    'parsing worked';
+is $data->{__error__}, undef, 'no errors';
+ok $data->{file_name}, 'received file name';
+ok $data->{body}, 'received file body';
+
+like $data->{body}, qr{domain\s+foo}, 'domain specification';
+like $data->{body}, qr{search\s+bar}, 'search specification';
+like $data->{body}, qr{nameserver\s+baz}, 'first nameserver specification';
+like $data->{body}, qr{nameserver\s+qux}, 'second nameserver specification';
 
 done_testing;