Commit | Line | Data |
60e1cc39 |
1 | package System::Introspector::Gatherer; |
2 | use Moo; |
a5e1e1c6 |
3 | use Object::Remote; |
4 | use Object::Remote::Future; |
5 | use System::Introspector::Gatherer::Bridge; |
60e1cc39 |
6 | use Module::Runtime qw( use_module ); |
7 | |
8 | sub gather { |
9 | my ($self, $class, $args) = @_; |
a5e1e1c6 |
10 | return use_module("System::Introspector::Probe::$class") |
60e1cc39 |
11 | ->new($args) |
12 | ->gather; |
13 | } |
14 | |
a5e1e1c6 |
15 | sub _new_direct { |
16 | my ($class, $remote) = @_; |
17 | return $class->new::on($remote); |
18 | } |
19 | |
20 | sub _new_bridged { |
21 | my ($class, $bridge, $remote) = @_; |
22 | return System::Introspector::Gatherer::Bridge->new::on($bridge, |
23 | remote_spec => $remote, |
24 | remote_class => $class, |
25 | ); |
26 | } |
27 | |
28 | sub new_from_spec { |
29 | my ($class, %arg) = @_; |
30 | my ($user, $host, $sudo_user) = @arg{qw( user host sudo_user )}; |
31 | my $sudo = defined($sudo_user) ? sprintf('%s@', $sudo_user) : undef; |
32 | if (defined $host) { |
33 | my $remote = join '@', grep defined, $user, $host; |
34 | if (defined $sudo_user) { |
35 | return $class->_new_bridged($remote, $sudo); |
36 | } |
37 | else { |
38 | return $class->_new_direct($remote); |
39 | } |
40 | } |
41 | else { |
42 | if (defined $sudo_user) { |
43 | return $class->_new_direct($sudo); |
44 | } |
45 | else { |
46 | return $class->new; |
47 | } |
48 | } |
49 | } |
50 | |
60e1cc39 |
51 | 1; |