Mercurial > pub > Impl
diff lib/IMPL/Config/Hierarchy.pm @ 413:af8d359ee4cc ref20150831
working on di container
author | cin |
---|---|
date | Thu, 24 Sep 2015 12:19:30 +0300 |
parents | 30e8c6a74937 |
children | ec6f2d389d1e |
line wrap: on
line diff
--- a/lib/IMPL/Config/Hierarchy.pm Mon Sep 21 19:54:10 2015 +0300 +++ b/lib/IMPL/Config/Hierarchy.pm Thu Sep 24 12:19:30 2015 +0300 @@ -50,16 +50,19 @@ my $cache = $this->{$_cache}{$role}; unless ($cache) { - $cache = {}; + $cache = { $role, 0 }; - my @roles = ($role); - + my @roles = [$role, 0]; + while (my $r = shift @roles ) { - next if $cache->{$r}; - - $cache->{$r} = 1; - if(my $parents = $this->{$roles}{$r}) { - push @roles, @$parents; + my ($name, $level) = @$r; + + $cache->{$name} = $level; + if(my $parents = $this->{$roles}{$name}) { + foreach my $p (@$parents) { + next if $cache{$p}; + push @roles, [$p, $cache{$p} = $level + 1]; + } } } $this->{$_cache}{$role} = $cache;