From: Robert 'phaylon' Sedlacek Date: Tue, 19 Jun 2012 21:56:39 +0000 (+0000) Subject: simplified ResolvConf probe output and make it conform to standard file data structure X-Git-Tag: v0.001_001~35 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=13642dda04be9f496ffbab2282f0268a6e7c9cbc;p=scpubgit%2FSystem-Introspector.git simplified ResolvConf probe output and make it conform to standard file data structure --- diff --git a/lib/System/Introspector/Probe/ResolvConf.pm b/lib/System/Introspector/Probe/ResolvConf.pm index 3417496..753085f 100644 --- a/lib/System/Introspector/Probe/ResolvConf.pm +++ b/lib/System/Introspector/Probe/ResolvConf.pm @@ -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__ diff --git a/t/resolvconf.t b/t/resolvconf.t index 1341e33..9d2d773 100644 --- a/t/resolvconf.t +++ b/t/resolvconf.t @@ -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;