package System::Introspector::Packages::Apt;
use Moo;

sub gather {
    my ($self) = @_;
    return {
        installed => $self->_gather_installed,
    };
}

sub _gather_installed {
    my ($self) = @_;
    my $command = "dpkg-query --show";
    open my $pipe, '-|', $command
        or die "Unable to open pipe to '$command': $!\n";
    my %package;
    while (defined( my $line = <$pipe> )) {
        chomp $line;
        my ($package, $version) = split m{\s+}, $line;
        $package{ $package } = {
            version => $version,
        };
    }
    return \%package;
}

1;
