Packages::Apt probe for gathering installed apt packages via dpkg-query
Robert 'phaylon' Sedlacek [Tue, 1 May 2012 19:52:45 +0000 (19:52 +0000)]
lib/System/Introspector/Packages/Apt.pm [new file with mode: 0644]

diff --git a/lib/System/Introspector/Packages/Apt.pm b/lib/System/Introspector/Packages/Apt.pm
new file mode 100644 (file)
index 0000000..f95e704
--- /dev/null
@@ -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;