Add `no_defaults_for' attribute to fix subcache get/set infinite recursion #24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
CHI subclasses that define one or more subcaches using
defaults
,namespace
, orstorage
are susceptible to infinite recursion uponget
andset
. Considerl1_loop.pl
:$ ./l1_loop.pl Deep recursion on subroutine "Role::Tiny::_COMPOSABLE::CHI::Driver::Role::HasSubcaches::set" at /home/matt/git/perl-chi/lib/CHI/Driver/Role/HasSubcaches.pm line 88. Deep recursion on anonymous subroutine at (eval 42) line 16. ^C
The reason is that the subcache is instantiated using the same defaults as the parent cache, so will have its own subcache, which has its own subcache, which has its own subcache, all the way down. This manifests as recursion on the
anonymous subroutine
s defined withbefore
andaround
inCHI::Driver::Role::HasSubcaches
.This pull requests addresses the infinite recursion issue by adding the constructor param
no_defaults_for
, which allows specifying a list of keys to delete from thedefaults
,namespace
, andstorage
hashrefs prior to instantiating a CHI subclass instance. All subcaches getl1_cache
andmirror_cache
automatically appended tono_defaults_for
-- only the parent cache can have subcaches defined from package defaults.Thanks in advance for considering this pull request!
P.S.: I got the following error when running
dzil build
:$ dzil build Can't call method "content" on an undefined value at /home/matt/opt/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0/Dist/Zilla/Plugin/MakeMaker.pm line 318.
I fixed this by editing
dist.ini
to removefilenames = Makefile.PL
from[PruneFiles]
and addexclude_filename = Makefile.PL
to[GatherDir]
. The real culprit might be some environment muck-up on my part -- please let me know :).