Commit | Line | Data |
97b10529 |
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 | |
3d4ae7f9 |
11 | sub _open_dpkg_query_pipe { |
97b10529 |
12 | my ($self) = @_; |
3d4ae7f9 |
13 | my $command = 'dpkg-query --show'; |
97b10529 |
14 | open my $pipe, '-|', $command |
15 | or die "Unable to open pipe to '$command': $!\n"; |
3d4ae7f9 |
16 | return $pipe; |
17 | } |
18 | |
19 | sub _gather_installed { |
20 | my ($self) = @_; |
21 | my $pipe = $self->_open_dpkg_query_pipe; |
97b10529 |
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; |