removed plain alarm timeout
[scpubgit/System-Introspector.git] / lib / System / Introspector / Gatherer.pm
CommitLineData
60e1cc39 1package System::Introspector::Gatherer;
2use Moo;
a5e1e1c6 3use Object::Remote;
4use Object::Remote::Future;
5use System::Introspector::Gatherer::Bridge;
60e1cc39 6use Module::Runtime qw( use_module );
7
949dba9c 8has introspectors => (is => 'ro', required => 1);
9
10sub gather_all {
11 my ($self) = @_;
12 my %report;
13 for my $spec (@{ $self->introspectors }) {
14 my ($base, $args) = @$spec;
15 $report{$base} = use_module("System::Introspector::Probe::$base")
16 ->new($args)
17 ->gather;
18 }
19 return \%report;
60e1cc39 20}
21
a5e1e1c6 22sub _new_direct {
949dba9c 23 my ($class, $remote, $args) = @_;
24 return $class->new::on($remote, $args || {});
a5e1e1c6 25}
26
27sub _new_bridged {
949dba9c 28 my ($class, $bridge, $remote, $args) = @_;
a5e1e1c6 29 return System::Introspector::Gatherer::Bridge->new::on($bridge,
30 remote_spec => $remote,
31 remote_class => $class,
949dba9c 32 remote_args => $args || {},
a5e1e1c6 33 );
34}
35
36sub new_from_spec {
37 my ($class, %arg) = @_;
38 my ($user, $host, $sudo_user) = @arg{qw( user host sudo_user )};
39 my $sudo = defined($sudo_user) ? sprintf('%s@', $sudo_user) : undef;
949dba9c 40 my $args = { introspectors => $arg{introspectors} };
a5e1e1c6 41 if (defined $host) {
42 my $remote = join '@', grep defined, $user, $host;
43 if (defined $sudo_user) {
949dba9c 44 return $class->_new_bridged($remote, $sudo, $args);
a5e1e1c6 45 }
46 else {
949dba9c 47 return $class->_new_direct($remote, $args);
a5e1e1c6 48 }
49 }
50 else {
51 if (defined $sudo_user) {
949dba9c 52 return $class->_new_direct($sudo, $args);
a5e1e1c6 53 }
54 else {
949dba9c 55 return $class->new($args);
a5e1e1c6 56 }
57 }
58}
59
60e1cc39 601;