made introspector executable
[scpubgit/System-Introspector.git] / lib / System / Introspector / Probe / ResolvConf.pm
1 package System::Introspector::Probe::ResolvConf;
2 use Moo;
3
4 use System::Introspector::Util qw(
5     handle_from_file
6     transform_exceptions
7 );
8
9 has resolv_conf_file => (
10     is      => 'ro',
11     default => sub { '/etc/resolv.conf' },
12 );
13
14 sub gather {
15     my ($self) = @_;
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     };
27 }
28
29 sub _open_resolv_conf_file {
30     my ($self) = @_;
31     return handle_from_file $self->resolv_conf_file;
32 }
33
34 1;
35
36 __END__
37
38 =head1 NAME
39
40 System::Introspector::ResolvConf - Gather name resolution configuration
41
42 =head1 DESCRIPTION
43
44 Reads a C<resolv.conf> file to gather information about name resolution.
45
46 =head1 ATTRIBUTES
47
48 =head2 resolv_conf_file
49
50 The path to the C<resolv.conf> file that should be read. Defaults to
51 C</etc/resolv.conf>.
52
53 =head1 SEE ALSO
54
55 =over
56
57 =item L<System::Introspector>
58
59 =back
60
61 =cut
62