use Moo;
use System::Introspector::Util qw(
- handle_from_file
+ output_from_file
transform_exceptions
);
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__
);
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;