Yes, I don't think Perl Mouse was suggesting it would get a prototype. But so what? Would adding a prototype solve any problems? Usually, the entire program has been compiled at that point already, so adding a prototype doesn't gain anything.

Yes, I don't think tye was suggesting that just adding a prototype would be enough to solve any problem. But so what? Would defining the function earlier solve any problems? The function doesn't have a prototype so defining it early doesn't gain anything. (:

But, in fact, you don't have to define the function earlier. You can still use "POSIX's autoloading behaviour" to delay the defining of the function's body, you just have to fix the exporting of the function to export a prototype (by declaring the function that you haven't defined yet).

Here's an example of how to do that making the bold assumption that all POSIX exported items with ALL_CAPS names are supposed to be constants (and mostly ignoring POSIX's current implementation for the sake of making a quick demonstration):

BEGIN { require POSIX; package POSIX; my $import= \&POSIX::import; *import= sub { warn "import( @_ )\n"; my( $pkg )= @_; eval "sub $_(); 1" || warn "$@" for grep /^[A-Z_]+$/, @_[1..$#_]; goto &$import; }; my $auto= \&POSIX::AUTOLOAD; *AUTOLOAD= sub { if( $AUTOLOAD =~ /^[A-Z_:]+$/ ) { warn "Auto-loading $AUTOLOAD.\n"; my $val = constant( ( split /::/, $AUTOLOAD )[-1] ); if( $! == 0 ) { goto &$AUTOLOAD if eval "sub $AUTOLOAD() { $val }; 1"; warn "$@"; } } goto &$auto; }; } use POSIX 'CHAR_MAX'; print "CHAR_MAX(", prototype("CHAR_MAX"), ")\n"; print CHAR_MAX+1, $/;

which outputs:

$ perl posix.pl import( POSIX CHAR_MAX ) CHAR_MAX() Auto-loading POSIX::CHAR_MAX. 128

Which shows that Perl was forced to autoload the function after the line that prints the prototype and yet the problem is fixed.

- tye        


In reply to Re^4: Beware of POSIX constants (sorta) by tye
in thread Beware of POSIX constants by tlm

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.