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 | |
949dba9c |
8 | has introspectors => (is => 'ro', required => 1); |
9 | |
10 | sub 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 |
22 | sub _new_direct { |
949dba9c |
23 | my ($class, $remote, $args) = @_; |
24 | return $class->new::on($remote, $args || {}); |
a5e1e1c6 |
25 | } |
26 | |
27 | sub _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 | |
36 | sub 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 |
60 | 1; |
f24afb0e |
61 | |
62 | __END__ |
63 | |
64 | =head1 NAME |
65 | |
66 | System::Introspector::Gatherer - Remote Gather Handler |
67 | |
68 | =head1 SEE ALSO |
69 | |
70 | =over |
71 | |
72 | =item L<System::Introspector> |
73 | |
74 | =back |
75 | |
76 | =head1 COPYRIGHT |
77 | |
78 | Copyright (c) 2012 the L<System::Introspector> |
79 | L<AUTHOR|System::Introspector/AUTHOR>, |
80 | L<CONTRIBUTORS|System::Introspector/CONTRIBUTORS> and |
81 | L<SPONSORS|System::Introspector/SPONSORS>. |
82 | |
83 | =head1 LICENSE |
84 | |
85 | This library is free software and may be distributed under the same terms |
86 | as perl itself. |
87 | |
88 | =cut |