determine unique perls by their sitelibexp config setting
[scpubgit/System-Introspector.git] / lib / System / Introspector / Probe / Host.pm
CommitLineData
afd7c030 1package System::Introspector::Probe::Host;
f473f1c2 2use Moo;
3
07a2389f 4use System::Introspector::Util qw(
5 handle_from_command
6 output_from_command
7 output_from_file
8 transform_exceptions
9);
10
b06b139d 11has hostname_file => (is => 'ro', default => sub {'/etc/hostname' });
12
f473f1c2 13sub gather {
14 my ($self) = @_;
07a2389f 15 return transform_exceptions {
16 return {
17 hostname => $self->_gather_hostname,
18 uname => $self->_gather_uname_info,
19 };
f473f1c2 20 };
21}
22
23my @UnameFields = qw(
24 kernel_name
25 kernel_release
26 kernel_version
27 nodename
28 machine
29 processor
30 hardware_platform
31 operating_system
32);
33
34sub _gather_uname_info {
35 my ($self) = @_;
36 my %uname;
37 for my $field (@UnameFields) {
38 (my $option = $field) =~ s{_}{-}g;
07a2389f 39 my $value = output_from_command [uname => "--$option"];
f473f1c2 40 chomp $value;
41 $uname{ $field } = $value;
42 }
43 return \%uname;
44}
45
46sub _gather_hostname {
47 my ($self) = @_;
b06b139d 48 my $hostname = output_from_file $self->hostname_file;
f473f1c2 49 chomp $hostname;
97d232ad 50 $hostname =~ s{(?:^\s+|\s+$)}{}g;
f473f1c2 51 return $hostname;
52}
53
541;
535e84b6 55
56__END__
57
58=head1 NAME
59
60System::Introspector::Host - Gather generic host information
61
62=head1 DESCRIPTION
63
64Gathers the hostname and information provided by C<uname>.
65
66=head1 SEE ALSO
67
68=over
69
70=item L<System::Introspector>
71
72=back
73
74=cut
75