From: Robert 'phaylon' Sedlacek Date: Tue, 1 May 2012 19:52:45 +0000 (+0000) Subject: Packages::Apt probe for gathering installed apt packages via dpkg-query X-Git-Tag: v0.001_001~141 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=97b1052983ea155f0d822abea73385d7325ae852;p=scpubgit%2FSystem-Introspector.git Packages::Apt probe for gathering installed apt packages via dpkg-query --- 97b1052983ea155f0d822abea73385d7325ae852 diff --git a/lib/System/Introspector/Packages/Apt.pm b/lib/System/Introspector/Packages/Apt.pm new file mode 100644 index 0000000..f95e704 --- /dev/null +++ b/lib/System/Introspector/Packages/Apt.pm @@ -0,0 +1,27 @@ +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;