P is for Practical | |
PerlMonks |
Prototypes required even after mocking a subby stevieb (Canon) |
on Sep 21, 2018 at 19:11 UTC ( [id://1222807]=perlquestion: print w/replies, xml ) | Need Help?? |
stevieb has asked for the wisdom of the Perl Monks concerning the following question: So, I had a user of my Mock::Sub distribution file an issue report where trying to mock a subroutine that has prototypes threw a warning. After monkeying about with it, I was able to quell said warnings, but it raised something else that I don't understand. I'll post some code and context, then get to what I'm hoping to have answered. This is a runnable example based on the snippet that the user reported:
Result:
All well and good. As a response to the user, I drummed up a test script with a signal handler to catch Prototype warnings, and just evaporate them (I'll incorporate this into the distribution directly if the reporter is satisfied, enabled only if requested explicitly):
That code does the right thing, insofar that the mocked sub is properly called and the prototype warnings are no longer displayed:
Now, what I found while testing, is that initially, I called foo() with no parameters, but the prototype stuck, resulting in fatality. Instead of foo(1, 2, 3); (proper number of params), I had just foo(), and...
All I do when I mock out a sub, is overwrite the symbol table for it (actual code from the module):
My question here, is if the symtab entry was overwritten correctly (ie. the mocked sub is most definitely called as desired), why does perl still think that it requires the prototyped parameters? Clearly, that information is stored somewhere, but where and how? Can someone point me in a direction I can look down to understand this, or even explain it to me? Thanks, as always, -stevieb
Back to
Seekers of Perl Wisdom
|
|