From f2b5d9bacf8e109fe27cea8f68232d41fd3b3ea5 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 17 Dec 2018 16:33:25 +0100 Subject: Make context parameter explicit This prevents a loop in $deps->{..}->{context} which is 1) unnecessary and 2) potentially breaks memory recovery when things get deleted. Not the case right now, but whatever. Signed-off-by: Florian Pritz --- lib/App/ArchLinux/PackagerTools.pm | 13 ++++++------- lib/App/ArchLinux/PackagerTools/CPAN.pm | 12 ++++++------ .../ArchLinux/PackagerTools/CPAN/PackagesDetailsFetcher.pm | 8 ++++---- lib/App/ArchLinux/PackagerTools/Cache.pm | 12 ++++++------ lib/App/ArchLinux/PackagerTools/Config.pm | 10 +++++----- lib/App/ArchLinux/PackagerTools/Pacman.pm | 8 ++++---- 6 files changed, 31 insertions(+), 32 deletions(-) (limited to 'lib/App') diff --git a/lib/App/ArchLinux/PackagerTools.pm b/lib/App/ArchLinux/PackagerTools.pm index 0fbd224..8fc22f9 100644 --- a/lib/App/ArchLinux/PackagerTools.pm +++ b/lib/App/ArchLinux/PackagerTools.pm @@ -37,15 +37,14 @@ App::ArchLinux::PackagerTools is ... Returns a new instance. =cut -method new($class: $deps = {}) { - $deps->{context} //= {}; - $deps->{config} //= App::ArchLinux::PackagerTools::Config->new({$deps->%{context}}); - $deps->{cpan} //= App::ArchLinux::PackagerTools::CPAN->new({$deps->%{context}}); - $deps->{pacman} //= App::ArchLinux::PackagerTools::Pacman->new({$deps->%{context}}); - return $class->new_no_defaults($deps); +method new($class: $context = {}, $deps = {}) { + $deps->{config} //= App::ArchLinux::PackagerTools::Config->new($context); + $deps->{cpan} //= App::ArchLinux::PackagerTools::CPAN->new($context); + $deps->{pacman} //= App::ArchLinux::PackagerTools::Pacman->new($context); + return $class->new_no_defaults($context, $deps); } -method new_no_defaults($class: $deps = {}) { +method new_no_defaults($class: $context, $deps = {}) { my $self = {}; bless $self, $class; $self->{deps} = $deps; diff --git a/lib/App/ArchLinux/PackagerTools/CPAN.pm b/lib/App/ArchLinux/PackagerTools/CPAN.pm index de2a397..c48469a 100644 --- a/lib/App/ArchLinux/PackagerTools/CPAN.pm +++ b/lib/App/ArchLinux/PackagerTools/CPAN.pm @@ -37,20 +37,20 @@ Returns a new instance. =cut -method new($class: $deps = {}) { - $deps->{packages_details_fetcher} //= App::ArchLinux::PackagerTools::CPAN::PackagesDetailsFetcher->new({$deps->%{context}}); - return $class->new_no_defaults($deps); +method new($class: $context, $deps = {}) { + $deps->{packages_details_fetcher} //= App::ArchLinux::PackagerTools::CPAN::PackagesDetailsFetcher->new($context); + return $class->new_no_defaults($context, $deps); } -method new_no_defaults($class: $deps = {}) { - return $deps->{context}->{$class} if defined $deps->{context}->{$class}; +method new_no_defaults($class: $context, $deps = {}) { + return $context->{$class} if defined $context->{$class}; my $self = {}; bless $self, $class; $self->{deps} = $deps; $self->{dist_lc_map} = {}; $self->{dists} = {}; - $deps->{context}->{$class} = $self; + $context->{$class} = $self; $log->debug("Initialized new CPAN object"); return $self; } diff --git a/lib/App/ArchLinux/PackagerTools/CPAN/PackagesDetailsFetcher.pm b/lib/App/ArchLinux/PackagerTools/CPAN/PackagesDetailsFetcher.pm index 734669c..88122da 100644 --- a/lib/App/ArchLinux/PackagerTools/CPAN/PackagesDetailsFetcher.pm +++ b/lib/App/ArchLinux/PackagerTools/CPAN/PackagesDetailsFetcher.pm @@ -30,12 +30,12 @@ Returns a new instance. =cut -method new($class: $deps = {}) { - $deps->{cache} //= App::ArchLinux::PackagerTools::Cache->new({$deps->%{context}}); - return $class->new_no_defaults($deps); +method new($class: $context, $deps = {}) { + $deps->{cache} //= App::ArchLinux::PackagerTools::Cache->new($context); + return $class->new_no_defaults($context, $deps); } -method new_no_defaults($class: $deps = {}) { +method new_no_defaults($class: $context, $deps = {}) { my $self = {}; bless $self, $class; $self->{deps} = $deps; diff --git a/lib/App/ArchLinux/PackagerTools/Cache.pm b/lib/App/ArchLinux/PackagerTools/Cache.pm index b8415ad..6d5bec3 100644 --- a/lib/App/ArchLinux/PackagerTools/Cache.pm +++ b/lib/App/ArchLinux/PackagerTools/Cache.pm @@ -31,13 +31,13 @@ Returns a new instance. =cut -method new($class: $deps = {}) { - $deps->{config} //= App::ArchLinux::PackagerTools::Config->new({$deps->%{context}}); - return $class->new_no_defaults($deps); +method new($class: $context, $deps = {}) { + $deps->{config} //= App::ArchLinux::PackagerTools::Config->new($context); + return $class->new_no_defaults($context, $deps); } -method new_no_defaults($class: $deps = {}) { - return $deps->{context}->{$class} if defined $deps->{context}->{$class}; +method new_no_defaults($class: $context, $deps = {}) { + return $context->{$class} if defined $context->{$class}; my $self = {}; bless $self, $class; @@ -50,7 +50,7 @@ method new_no_defaults($class: $deps = {}) { root_dir => $config->{cache}->{root_dir}, cache_size => $config->{cache}->{cache_size}, ); - $deps->{context}->{$class} = $self; + $context->{$class} = $self; return $self; } diff --git a/lib/App/ArchLinux/PackagerTools/Config.pm b/lib/App/ArchLinux/PackagerTools/Config.pm index 470a1ae..a58e82d 100644 --- a/lib/App/ArchLinux/PackagerTools/Config.pm +++ b/lib/App/ArchLinux/PackagerTools/Config.pm @@ -32,17 +32,17 @@ Returns a new instance. =cut -method new($class: $deps = {}) { - return $class->new_no_defaults($deps); +method new($class: $context, $deps = {}) { + return $class->new_no_defaults($context, $deps); } -method new_no_defaults($class: $deps = {}) { - return $deps->{context}->{$class} if defined $deps->{context}->{$class}; +method new_no_defaults($class: $context, $deps = {}) { + return $context->{$class} if defined $context->{$class}; my $self = {}; bless $self, $class; $self->{deps} = $deps; - $deps->{context}->{$class} = $self; + $context->{$class} = $self; return $self; } diff --git a/lib/App/ArchLinux/PackagerTools/Pacman.pm b/lib/App/ArchLinux/PackagerTools/Pacman.pm index f541721..3204ca1 100644 --- a/lib/App/ArchLinux/PackagerTools/Pacman.pm +++ b/lib/App/ArchLinux/PackagerTools/Pacman.pm @@ -35,17 +35,17 @@ Returns a new instance. =cut -method new($class: $deps = {}) { - $deps->{cpan} //= App::ArchLinux::PackagerTools::CPAN->new({$deps->%{context}}); +method new($class: $context, $deps = {}) { + $deps->{cpan} //= App::ArchLinux::PackagerTools::CPAN->new($context); $deps->{pkgname_cpan_name_map} //= { # pkgname => cpan_name 'perl-critic' => 'Perl::Critic', 'perl-libintl-perl' => 'libintl-perl', }; - return $class->new_no_defaults($deps); + return $class->new_no_defaults($context, $deps); } -method new_no_defaults($class: $deps = {}) { +method new_no_defaults($class: $context, $deps = {}) { my $self = {}; bless $self, $class; $deps->{cpan_name_pkgname_map} = {reverse $deps->{pkgname_cpan_name_map}->%*}; -- cgit v1.2.3-24-g4f1b