From: Robert 'phaylon' Sedlacek Date: Wed, 3 Oct 2012 21:08:31 +0000 (+0000) Subject: make reporting of known but uninstalled packages optional X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=576b42783dc7fb3c332d0c3cd237be53203cfd28;p=scpubgit%2FSystem-Introspector-Report.git make reporting of known but uninstalled packages optional --- diff --git a/lib/System/Introspector/Report/Builder/Packages/Apt/ByHost.pm b/lib/System/Introspector/Report/Builder/Packages/Apt/ByHost.pm index 9398c98..fc9e23a 100644 --- a/lib/System/Introspector/Report/Builder/Packages/Apt/ByHost.pm +++ b/lib/System/Introspector/Report/Builder/Packages/Apt/ByHost.pm @@ -3,9 +3,10 @@ use Moo; extends 'System::Introspector::Report::Builder'; -has _known_package => (is => 'ro', default => sub { {} }); -has _host_package => (is => 'ro', default => sub { {} }); -has _host_upgrade => (is => 'ro', default => sub { {} }); +has _known_package => (is => 'ro', default => sub { {} }); +has _host_package => (is => 'ro', default => sub { {} }); +has _host_upgrade => (is => 'ro', default => sub { {} }); +has include_uninstalled => (is => 'ro'); sub required_data { return qw( @@ -34,6 +35,7 @@ sub render_reports { my $host_package = $self->_host_package; my $host_upgrade = $self->_host_upgrade; my @known_packages = sort keys %{$self->_known_package}; + my $inc_uninstalled = $self->include_uninstalled; return map { my $remote = $_; +{ @@ -54,6 +56,10 @@ sub render_reports { defined($version) ? (version => $version) : (), defined($upgrade) ? (upgrade => $upgrade) : (), }; + } grep { + $inc_uninstalled + ? 1 + : defined($host_package->{$remote}{$_}); } @known_packages], }; } sort keys %{$self->_host_package}; diff --git a/t/builder_packages-apt-byhost.t b/t/builder_packages-apt-byhost.t index 0fed0a1..5e1a0c9 100644 --- a/t/builder_packages-apt-byhost.t +++ b/t/builder_packages-apt-byhost.t @@ -4,7 +4,9 @@ use FindBin; use aliased 'System::Introspector::Report::Source'; my $source = Source->new(root => "$FindBin::Bin/data/json/"); -my @reports = $source->generate(['Packages::Apt::ByHost', {}]); +my @reports = $source->generate(['Packages::Apt::ByHost', { + include_uninstalled => 1, +}]); is scalar(@reports), 2, 'two reports received';