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

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.

Replies are listed 'Best First'.
Re^4: list all subs in a package
by sflitman (Hermit) on Jan 02, 2009 at 09:55 UTC
    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)