in reply to Re: list all subs in a package
in thread list all subs in a package

Thank you. I think baz isn't listed by design because it is a constant function with a length zero prototype. If the lines my $proto... and next if defined are commented out, baz is listed.

bar should be listed, even though it is a stub, since its symbol table glob will have something in its CODE slot, and then package TestB inherits a glob *bar which gets vivified by inheritance (is that right?) when you mention our $bar

SSF

Replies are listed 'Best First'.
Re^3: list all subs in a package
by ikegami (Patriarch) on Jan 02, 2009 at 02:56 UTC

    I think baz isn't listed by design because it is a constant function with a length zero prototype.

    It's not. It has a length zero prototype, but it's not constant. The intent of the code is to remove constants since someone listing the subs in a package probably doesn't consider them to be subs. But there's no doubt that they would consider baz to be a sub. It should be listed.

    bar should be listed

    Depending on the purpose of the function, either both foo and bar should be listed or neither should be listed. It doesn't make sense to list one (foo) and not the other (bar).

    Turns out foo does get listed as part of TestB some of the time. If it hasn't been called yet, it won't show in TestB. If it has been called via TestB, it'll show in TestB. That doesn't make sense either. Either foo is a subroutine or method of TestB or its not. That's not dependent on whether it's been called or not.

      That's interesting. How would I detect a non-constant sub with length zero prototype? Or, more generally, how would I distinguish between a true constant function and a function like baz?

        I don't think it's possible without some XS code, but the information appears to be present.

        >perl -MDevel::Peek -e"sub X() { time } Dump \&X" SV = PVCV(0x182647c) at 0x1831628 FLAGS = (POK,pPOK) >perl -MDevel::Peek -e"sub X() { 1 } Dump \&X" SV = PVCV(0x1833acc) at 0x1831688 FLAGS = (POK,pPOK,CONST)

        (Irrelevant bits filtered out)