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