1 package System::Introspector::Probe::Packages::Apt;
4 use System::Introspector::Util qw(
9 has apt_lists_dir => (is => 'ro', builder => 1);
10 has apt_update_after => (is => 'ro', default => sub { 86400 });
11 has apt_update => (is => 'ro');
13 sub _build_apt_lists_dir { '/var/lib/apt/lists' }
19 last => $self->_last_apt_update,
20 run => transform_exceptions {
21 return { result => $self->_check_apt_state };
24 installed => transform_exceptions {
25 return { packages => $self->_gather_installed };
27 upgradable => transform_exceptions {
28 return { actions => $self->_gather_upgradable };
33 sub _last_apt_update {
35 return scalar( (stat($self->apt_lists_dir))[9] );
38 sub _check_apt_state {
40 return 'disabled' unless $self->apt_update;
41 my $threshold = $self->apt_update_after;
42 my $last_change = $self->_last_apt_update;
43 return 'no'if ($last_change + $threshold) > time;
44 handle_from_command 'apt-get update';
48 sub _open_dpkg_query_pipe {
50 return handle_from_command 'dpkg-query --show';
53 sub _open_apt_get_upgrade_simulation_pipe {
55 return handle_from_command 'apt-get -s upgrade';
58 sub _gather_upgradable {
60 my $pipe = $self->_open_apt_get_upgrade_simulation_pipe;
62 while (defined( my $line = <$pipe> )) {
64 if ($line =~ m{^(inst|remv)\s+(\S+)\s+(.+)$}i) {
65 $action{ lc($1) }{ $2 } = $3;
71 sub _gather_installed {
73 my $pipe = $self->_open_dpkg_query_pipe;
75 while (defined( my $line = <$pipe> )) {
77 my ($package, $version) = split m{\s+}, $line;
78 $package{ $package } = {
91 System::Introspector::Packages::Apt - Gather APT package status
95 Uses C<dpkg-query> to list all installed packages.
101 =item L<System::Introspector>