Mercurial > pub > Impl
diff lib/IMPL/Config/Bag.pm @ 417:3ed0c58e9da3 ref20150831
working on di container, tests
author | cin |
---|---|
date | Mon, 02 Nov 2015 01:56:53 +0300 |
parents | 3d24b10dd0d5 |
children | b0481c071bea |
line wrap: on
line diff
--- a/lib/IMPL/Config/Bag.pm Thu Oct 29 03:50:25 2015 +0300 +++ b/lib/IMPL/Config/Bag.pm Mon Nov 02 01:56:53 2015 +0300 @@ -41,9 +41,9 @@ } sub _Seal { - unless ($_[0]->{$_sealed}) { - $_[0]->{$_sealed} = 1; - $_[0]->{$_timestamp} = 0; # from now the timestamp is important + unless ( $_[0]->{$_sealed} ) { + $_[0]->{$_sealed} = 1; + $_[0]->{$_timestamp} = 0; # from now the timestamp is important } } @@ -53,19 +53,20 @@ my $chain = $this->{$_parents} or return 1; - my $rev = 0; # rev 0 means that parent was never modified - # this allows to made more efficient checks + my $rev = 0; # rev 0 means that parent was never modified + # this allows to made more efficient checks my $flush; - - foreach my $bag (@$chain, $this) { + + foreach my $bag ( @$chain, $this ) { + # we need to updated all bags after the first change was detected; - if ($flush ||= $rev and $bag->{$_parentRev} != $rev) { - $bag->{$_cache} = {}; - $bag->{$_parentRev} = $rev; - } - $rev = $bag->{$_timestamp}; + if ( $flush ||= $rev and $bag->{$_parentRev} != $rev ) { + $bag->{$_cache} = {}; + $bag->{$_parentRev} = $rev; + } + $rev = $bag->{$_timestamp}; } - + return $flush ? 0 : 1; } @@ -105,29 +106,30 @@ $d = undef; my $prev; - if ( my $parents = $this->{$_parents} ) { - foreach my $bag ( @$parents, $this ) { + my $parents = $this->{$_parents}; + my @bags = $parents ? ( @$parents, $this ) : ($this); - # check the cache; - unless ( my $t = $bag->{$_cache}{$role} ) { + foreach my $bag (@bags) { + + # check the cache; + unless ( my $t = $bag->{$_cache}{$role} ) { # no cached entry this may be due cache flush # go through own entries and find better entry than inherited from parents - foreach my $entry ( @{ $bag->{$_entries} } ) { - my $level = $entry->{isa}{$role}; - if ( $level and ( not($prev) or $level <= $prev ) ) { - $d = $entry; - $prev = $level; - } + foreach my $entry ( @{ $bag->{$_entries} } ) { + my $level = $entry->{isa}{$role}; + if ( $level and ( not($prev) or $level <= $prev ) ) { + $d = $entry; + $prev = $level; } + } - #cache it - $bag->{$_cache}{$role} = $d if $d; - } - else { - $d = $t; - $prev = $d->{isa}{$role}; - } + #cache it + $bag->{$_cache}{$role} = $d if $d; + } + else { + $d = $t; + $prev = $d->{isa}{$role}; } } @@ -140,7 +142,7 @@ return [ map $_->{value}, grep $_->{isa}{$role}, - map @{$_->{$_entries}}, + map @{ $_->{$_entries} }, @{ $this->{$_parents} || [] }, $this ];