0e222a933995fd0413f4c07b497e7c6c19b378ac
[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 _open_dpkg_query_pipe {
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     return $pipe;
17 }
18
19 sub _gather_installed {
20     my ($self) = @_;
21     my $pipe = $self->_open_dpkg_query_pipe;
22     my %package;
23     while (defined( my $line = <$pipe> )) {
24         chomp $line;
25         my ($package, $version) = split m{\s+}, $line;
26         $package{ $package } = {
27             version => $version,
28         };
29     }
30     return \%package;
31 }
32
33 1;