only wrap our own errors
[scpubgit/System-Introspector.git] / lib / System / Introspector / Host.pm
CommitLineData
f473f1c2 1package System::Introspector::Host;
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
f473f1c2 11sub gather {
12 my ($self) = @_;
07a2389f 13 return transform_exceptions {
14 return {
15 hostname => $self->_gather_hostname,
16 uname => $self->_gather_uname_info,
17 };
f473f1c2 18 };
19}
20
21my @UnameFields = qw(
22 kernel_name
23 kernel_release
24 kernel_version
25 nodename
26 machine
27 processor
28 hardware_platform
29 operating_system
30);
31
32sub _gather_uname_info {
33 my ($self) = @_;
34 my %uname;
35 for my $field (@UnameFields) {
36 (my $option = $field) =~ s{_}{-}g;
07a2389f 37 my $value = output_from_command [uname => "--$option"];
f473f1c2 38 chomp $value;
39 $uname{ $field } = $value;
40 }
41 return \%uname;
42}
43
44sub _gather_hostname {
45 my ($self) = @_;
07a2389f 46 my $hostname = output_from_file '/etc/hostname';
f473f1c2 47 chomp $hostname;
48 return $hostname;
49}
50
511;
535e84b6 52
53__END__
54
55=head1 NAME
56
57System::Introspector::Host - Gather generic host information
58
59=head1 DESCRIPTION
60
61Gathers the hostname and information provided by C<uname>.
62
63=head1 SEE ALSO
64
65=over
66
67=item L<System::Introspector>
68
69=back
70
71=cut
72