Packages::Apt probe for gathering installed apt packages via dpkg-query
[scpubgit/System-Introspector.git] / lib / System / Introspector / Packages / Apt.pm
1 package System::Introspector::Packages::Apt;
2 use Moo;
3
4 sub gather {
5     my ($self) = @_;
6     return {
7         installed => $self->_gather_installed,
8     };
9 }
10
11 sub _gather_installed {
12     my ($self) = @_;
13     my $command = "dpkg-query --show";
14     open my $pipe, '-|', $command
15         or die "Unable to open pipe to '$command': $!\n";
16     my %package;
17     while (defined( my $line = <$pipe> )) {
18         chomp $line;
19         my ($package, $version) = split m{\s+}, $line;
20         $package{ $package } = {
21             version => $version,
22         };
23     }
24     return \%package;
25 }
26
27 1;