[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

possible ":method" bug/misfeature



Given this code:

    sub oct { 042 }
    $n = oct(9999);
    print "n is $n\n";

We can diagnose/generate these problems:

    % perl -wc /tmp/testmeth
    Ambiguous call resolved as CORE::oct(), qualify as such or use & at /tmp/testmeth line 2.
    Illegal octal digit '9' ignored at /tmp/testmeth line 2.
    /tmp/testmeth syntax OK

The documentation for `use attributes' specifies that include "method" in
the list of properties supresses that warning; and that, it does:

    % perl -wc /tmp/testmeth
    Illegal octal digit '9' ignored at /tmp/testmeth line 2.
    /tmp/testmeth syntax OK

Here's the issue: I fail to see *why* it suppresses that warning,
as it still applies.

    % ./perl -I lib -w /tmp/testmeth
    Illegal octal digit '9' ignored at /tmp/testmeth line 2.
    n is 0

After all, I'm still using the sub through a normal function call,
not as a method call.

I can't get away with using an method call on it either, passing 
the current package in the dative slot:

    sub oct : method { 042 }
    $n = oct __PACKAGE__ 9999;
    print "n is $n\n";

Since that produces this:

    % perl -wc /tmp/testmeth
    Number found where operator expected at /tmp/testmeth line 2, near "__PACKAGE__ 9999"
	    (Do you need to predeclare __PACKAGE__?)
    syntax error at /tmp/testmeth line 2, near "__PACKAGE__ 9999"
    /tmp/testmeth had compilation errors.

[Hey, what's this nonsense about "predeclaring __PACKAGE__"?)

If I use the arrowladen notation, of course, this is no problem:

    sub oct : method { 042 }
    $n = __PACKAGE__ -> oct(9999);
    print "n is $n\n";

    % perl -w /tmp/testmeth
    n is 34

But in that case, the :method attr is irrelevant:

    sub oct { 042 }
    $n = __PACKAGE__ -> oct(9999);
    print "n is $n\n";

    % perl -w /tmp/testmeth
    n is 34

So I don't see that the property of the :method attribute to suppress
the "ambiguous call resolved..." warning serves any useful purpose.
It seems to be at best misleading, since it doesn't help disambiguate
a function call in the same package--that function is still neglected.

If you really want this to be your own call, you have to employ the
use subs pragma:

    use subs qw/oct/;
    sub oct { 042 }
    $n = oct(9999);
    print "n is $n\n";

    % perl -w /tmp/testmeth
    n is 34

And without the declaration, a method call never triggers the
complaint anyway.  I had thought it might matter in the indirect
object situation, but this is apparently not the case.  So what
good, then, is :method really--beyond its interaction with :locked?

thanks,

--tom


Follow-Ups from:
Spider Boardman <spider-perl@Orb.Nashua.NH.US>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]