in reply to Prototype Failing?

Prototypes are not honoured on method calls. You passed an array and received and array. For the low-down on why, read on in the same document to the secion that starts

Method calls are not influenced by prototypes either, ...

Examine what is said, not who speaks.

The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

Replies are listed 'Best First'.
Re: Re: Prototype Failing?
by Flame (Deacon) on Jan 27, 2003 at 04:49 UTC
    Ok, so the first call was as a method, but the second was internal... a method calling a function, shouldn't it have honored the prototype then?

    _self is the only one with a prototype that needs to be payed attention to and it's being called as a function.



    My code doesn't have bugs, it just develops random features.

    Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

      The first argument in @_ in a method call is self.

      When you call _self(@_) you are passing a reference to an array, the first element of which is a bless'd reference. (in this case a hashref).

      When you give the array ref to Dumper, it duly dumps contents of the hash followed by the individual elements of the rest of @_. Ie. the list you passed to selftest().

      When you try to dereference the first element of @_ as an array ref in ref($_[0]->[0]), it complains because $_[0] is a hashref (self) as magically supplied to selftest() when you invoked it as a method.

      Hope that makes sense of it.


      Examine what is said, not who speaks.

      The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

        Sorry, you lost me there, but it's ok... It's working now (Re: Prototype Failing?)

        The problem was, it wasn't being convered to a reference, otherwise @_ would have dumped as a reference instead of $VAR1 $VAR2 $VAR...



        My code doesn't have bugs, it just develops random features.

        Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

        Actually, the call to $result= function(@some_args); is not a "method call" even if the first item in the array will subsequently be treated as an object. This is a regular function call, and will use normal sub lookup rules. It is semantically different from writing $some_args[0]->function(@some_args[1..$#some_args]); which will use the virtual calling mechanism and blessings to figure out which package's function to call first (and meanwhile ignore any prototypes).

        The real answer here is: use strict; use warnings; It will tell you that the prototype is ignored and why!