techra has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm trying to research a possible bug in the standard Perl module SelfLoader. Perhaps it's not considered a bug, but it seems awfully suspect to me. I've tried this with Perl version 5.8.4 and SelfLoader 1.0904 (the most recent).

Given the following:
package goober; use SelfLoader; sub goober::denote; 1; __DATA__ sub denote { # denote code }

SelfLoader does fine. But if one were to put a tab before the "sub denote {" line, and a script that uses the package of goober attempts to run the denote subroutine, it is not found.

As the tab is just whitespace, isn't this unusual behavior? Is it possibly a bug in the regular expressions SelfLoader uses to locate the actual subroutine declarations in a module?

When I remove the tab, everything works fine again.

I appreciate any edification on this matter.

d. Taylor Singletary,
reality technician

Replies are listed 'Best First'.
Re: Possible bug in SelfLoader?
by dragonchild (Archbishop) on Feb 17, 2005 at 19:00 UTC
    It's not a bug in the regular expression for SelfLoader - it's an undocumented requirement (which could be considered a documentation bug).

    The regex used requires that the sub declaration be anchored to the left column. I personally don't see a reason to do it that way and not allow optional whitespace between the '^' and 'sub' - maybe you should open a request at http://rt.cpan.org and/or email the author?

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      I'd actually keep the no-whitespace requirement considering such simple problems like:

      eval q{ sub foo1 { ... } ); print <<END; You'll need to define your method like: sub myMethod { ... } END use strict; { my $static; sub usesStatic { # Note that this routine fails if it # gets moved out of this lexical scope. return $static; } }

      It isn't perfect, but I find the no-whitespace requirement much saner.

      - tye