better users probe
[scpubgit/System-Introspector.git] / lib / System / Introspector / Probe / ResolvConf.pm
CommitLineData
afd7c030 1package System::Introspector::Probe::ResolvConf;
9cebf8c1 2use Moo;
3
f3d816a0 4use System::Introspector::Util qw(
5 handle_from_file
6 transform_exceptions
7);
8
21fd4f46 9has resolv_conf_file => (
10 is => 'ro',
11 default => sub { '/etc/resolv.conf' },
12);
13
9cebf8c1 14sub gather {
15 my ($self) = @_;
f3d816a0 16 return transform_exceptions {
17 my $fh = $self->_open_resolv_conf_file;
18 my @resolv;
19 while (defined( my $line = <$fh> )) {
20 chomp $line;
21 next if $line =~ m{^\s*$}
22 or $line =~ m{^\s*#};
23 push @resolv, [split m{\s+}, $line];
24 }
25 return { resolv_conf => \@resolv };
26 };
9cebf8c1 27}
28
29sub _open_resolv_conf_file {
30 my ($self) = @_;
f3d816a0 31 return handle_from_file $self->resolv_conf_file;
9cebf8c1 32}
33
341;
535e84b6 35
36__END__
37
38=head1 NAME
39
40System::Introspector::ResolvConf - Gather name resolution configuration
41
42=head1 DESCRIPTION
43
44Reads a C<resolv.conf> file to gather information about name resolution.
45
46=head1 ATTRIBUTES
47
48=head2 resolv_conf_file
49
50The path to the C<resolv.conf> file that should be read. Defaults to
51C</etc/resolv.conf>.
52
53=head1 SEE ALSO
54
55=over
56
57=item L<System::Introspector>
58
59=back
60
61=cut
62