moved probe classes to ::Probe:: namespace
[scpubgit/System-Introspector.git] / lib / System / Introspector / Probe / Packages / Apt.pm
1 package System::Introspector::Probe::Packages::Apt;
2 use Moo;
3
4 use System::Introspector::Util qw(
5     handle_from_command
6     transform_exceptions
7 );
8
9 sub gather {
10     my ($self) = @_;
11     return {
12         installed => transform_exceptions {
13             return { packages => $self->_gather_installed };
14         },
15     };
16 }
17
18 sub _open_dpkg_query_pipe {
19     my ($self) = @_;
20     return handle_from_command 'dpkg-query --show';
21 }
22
23 sub _gather_installed {
24     my ($self) = @_;
25     my $pipe = $self->_open_dpkg_query_pipe;
26     my %package;
27     while (defined( my $line = <$pipe> )) {
28         chomp $line;
29         my ($package, $version) = split m{\s+}, $line;
30         $package{ $package } = {
31             version => $version,
32         };
33     }
34     return \%package;
35 }
36
37 1;
38
39 __END__
40
41 =head1 NAME
42
43 System::Introspector::Packages::Apt - Gather APT package status
44
45 =head1 DESCRIPTION
46
47 Uses C<dpkg-query> to list all installed packages.
48
49 =head1 SEE ALSO
50
51 =over
52
53 =item L<System::Introspector>
54
55 =back
56
57 =cut