made introspector executable
[scpubgit/System-Introspector.git] / lib / System / Introspector / Probe / Packages / Apt.pm
CommitLineData
afd7c030 1package System::Introspector::Probe::Packages::Apt;
97b10529 2use Moo;
3
9ee104cc 4use System::Introspector::Util qw(
5 handle_from_command
6 transform_exceptions
7);
8
97b10529 9sub gather {
10 my ($self) = @_;
11 return {
9ee104cc 12 installed => transform_exceptions {
13 return { packages => $self->_gather_installed };
14 },
97b10529 15 };
16}
17
3d4ae7f9 18sub _open_dpkg_query_pipe {
97b10529 19 my ($self) = @_;
9ee104cc 20 return handle_from_command 'dpkg-query --show';
3d4ae7f9 21}
22
23sub _gather_installed {
24 my ($self) = @_;
25 my $pipe = $self->_open_dpkg_query_pipe;
97b10529 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
371;
535e84b6 38
39__END__
40
41=head1 NAME
42
43System::Introspector::Packages::Apt - Gather APT package status
44
45=head1 DESCRIPTION
46
47Uses 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