X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FClass%2FC3%2FComponentised.pm;h=a5c3b992ca7851ea828c021bb0a181faaf083ee3;hb=e6b8b400a35fbeab4b07c8f2fb5d7df72040f382;hp=58f9f2beba9e9f7d7e58392057b8a445a9af99f3;hpb=06e2d1023bce4f19c1f88c9363b9cf55de8ad255;p=p5sagit%2FClass-C3-Componentised.git diff --git a/lib/Class/C3/Componentised.pm b/lib/Class/C3/Componentised.pm index 58f9f2b..a5c3b99 100644 --- a/lib/Class/C3/Componentised.pm +++ b/lib/Class/C3/Componentised.pm @@ -188,13 +188,40 @@ sub inject_base { my $class = shift; my $target = shift; - for (reverse @_) { + mro::set_mro($target, 'c3'); + + for my $comp (reverse @_) { no strict 'refs'; - unshift ( @{"${target}::ISA"}, $_ ) - unless ($target eq $_ || $target->isa($_)); - } + unless ($target eq $comp || $target->isa($comp)) { + my @heritage = @{mro::get_linear_isa($comp)}; + + my @before = map { + my $to_run = $Class::C3::Componentised::ApplyHooks::Before{$_}; + ($to_run?[$_,$to_run]:()) + } @heritage; + + for my $todo (@before) { + my ($parent, $fn) = @$todo; + for my $f (reverse @$fn) { + $target->$f($parent) + } + } - mro::set_mro($target, 'c3'); + unshift ( @{"${target}::ISA"}, $comp ); + + my @after = map { + my $to_run = $Class::C3::Componentised::ApplyHooks::After{$_}; + ($to_run?[$_,$to_run]:()) + } @heritage; + + for my $todo (reverse @after) { + my ($parent, $fn) = @$todo; + for my $f (@$fn) { + $target->$f($parent) + } + } + } + } } =head2 load_optional_class