in reply to Re: Re: Prototype Failing?
in thread Prototype Failing?

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.

Replies are listed 'Best First'.
Re: Re: Re: Re: Prototype Failing?
by John M. Dlugosz (Monsignor) on Jan 27, 2003 at 07:00 UTC
    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!

      True, but your looking in the wrong place. This line from the OP

      $chk->selftest(qw(This Is a Test of the emergency broadcast system!));

      is a method call. It's from this call that the sequence of events that lead to the error reported

      Not an ARRAY reference at OO.pm line 264.

      and is the starting point for the sequence of events that I outlined, that explains the error message.


      Examine what is said, not who speaks.

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

      Actually, I had both strict and warnings active and recieved no message.



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

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

Re: Re: Re: Re: Prototype Failing?
by Flame (Deacon) on Jan 27, 2003 at 05:08 UTC
    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)