in reply to Need help with clashing method names
More specifically, the statement use B qw(moo) adds "moo" to the A namespace, thus defining A::moo(...) - this means that class A now has its own definition moo that overrides anything it inherits from C. Thus when you called A->new the code with variables resolved looked something like this:
my $self=bless({},"A"); $self->moo; #equivalent to $self->A::moo
A::moo(...) just happens to be an alias for B::moo(...) so you get the print out "B::moo" rather than "C::moo".
The lesson: if you don't want subroutine "foo" to magically become part of class "baz", don't import it into "baz"'s namespace. The best way to prevent this is to follow Almut's advice and use the incantation use B () whenever you import a class, unless you know that it is well behaved and doesn't auto-export anything.
Of course, if you want "blah::foo" to be a method of Class "baz", you can call use blah qw(foo) without fear.
Best, beth
|
|---|