So you have a theModule.pm and a X.pm. That are the modules, the files. But for method calls, it's the package, AKA the class, that $self is blessed in which matters, assuming it's an object. You don't mention the packages in the modules at all. Assuming $self is blessed in theModule.pm's package, say, "theModule", then of course the sub theModule::funcB that gets called as a method. If it were blessed in X.pm's class, say "X", then X::funcB would be called. That simple scheme ignores inheritance, i.e. how each package's @ISA array relates, but since each module, er, package, has a funcB method, I don't think it matters much. There must be some relationship, how else would the method funcA in theModule get called in the first place.

You can override normal method lookup, like $self->X::funcB(). I think there recently was a thread on PerlMonks about it. It's an extension to the slightly more orthodox $self->SUPER::funcB() call mechanism.
Update: found it: Invoking method in another package.

Try this, all in one single script — which again shows that it's the package the method is in, that matters, not the source file. The BEGIN block for the assignment to @theModule::ISA is only to make sure it is set when the main code runs, as the module definition is underneath the main code in the script source.

$obj = new theModule; $obj->funcA('own'); $obj->funcA('X'); $obj->funcA('SUPER'); package theModule; BEGIN { @ISA = 'Y'; } sub new { my %self; return bless \%self, shift; } sub funcA { my $self = shift; my $param = shift; print "\nfuncA in theModule got called, param = $param\n"; if($param eq 'own') { $self->funcB; } elsif($param eq 'X') { $self->X::funcB; } elsif($param eq 'SUPER') { $self->SUPER::funcB; } } sub funcB { my $self = shift; print "funcB in theModule is called\n"; } package X; sub funcB { my $self = shift; print "funcB in X is called\n"; } package Y; sub funcB { my $self = shift; print "funcB in Y is called\n"; }
This prints:
funcA in theModule got called, param = own funcB in theModule is called funcA in theModule got called, param = X funcB in X is called funcA in theModule got called, param = SUPER funcB in Y is called

In reply to Re: perl calls unexpected function by bart
in thread perl calls unexpected function by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.