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; |
535e84b6 |
34 | |
35 | __END__ |
36 | |
37 | =head1 NAME |
38 | |
39 | System::Introspector::Packages::Apt - Gather APT package status |
40 | |
41 | =head1 DESCRIPTION |
42 | |
43 | Uses C<dpkg-query> to list all installed packages. |
44 | |
45 | =head1 SEE ALSO |
46 | |
47 | =over |
48 | |
49 | =item L<System::Introspector> |
50 | |
51 | =back |
52 | |
53 | =cut |