simplified hosts to be standard file data structure, also preserves comments
[scpubgit/System-Introspector.git] / lib / System / Introspector / Probe / Hosts.pm
1 package System::Introspector::Probe::Hosts;
2 use Moo;
3
4 use System::Introspector::Util qw(
5     output_from_file
6     transform_exceptions
7 );
8
9 has hosts_file => (
10     is      => 'ro',
11     default => sub { '/etc/hosts' },
12 );
13
14 sub gather {
15     my ($self) = @_;
16     my $file = $self->hosts_file;
17     return {
18         hosts_file => transform_exceptions {
19             return {
20                 file_name => $file,
21                 body => scalar output_from_file $file,
22             };
23         },
24     };
25 }
26
27 1;
28
29 __END__
30
31 =head1 NAME
32
33 System::Introspector::Hosts - Gather known hosts
34
35 =head1 DESCRIPTION
36
37 Reads a C<hosts> file to produce a list of known hosts
38
39 =head1 ATTRIBUTES
40
41 =head2 hosts_file
42
43 The path to the C<hosts> file that should be read. Defaults to C</etc/hosts>.
44
45 =head1 SEE ALSO
46
47 =over
48
49 =item L<System::Introspector>
50
51 =back
52
53 =cut
54