Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: It is not an array!

by premchai21 (Curate)
on Nov 18, 2002 at 04:42 UTC ( #213655=note: print w/ replies, xml ) Need Help??


in reply to It is not an array!

My guess is that the object might not be being blessed properly, but without being able to see the Module::Name::new function, there's not much I (we?) can tell about it. Could you post it please?


Comment on Re: It is not an array!
Re: Re: It is not an array!
by hardburn (Abbot) on Nov 19, 2002 at 01:38 UTC

    This was the constructor:

    sub new { my ($class, %parameters) = \@_; my $self = bless ({}, ref ($class) || $class); return ($self); }

    This came right out of ExtUtils::ModuleMaker. After reading some of the comments in this node, I flipped through the Camel and found this suggestion:

    sub new { my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = { }; bless($self, $class); return $self; }

    Which appears to me to do basically the same thing (except it's not taking a hashref as a param, which shouldn't matter, and I don't need it anyway). However, the tests all pass with this version.

      I see what is going on now. This line:
      my ($class, %parameters) = \@_;
      makes a reference to the array @_, and assigns $class that reference. %parameters is left blank. Calling ref on an unblessed array reference returns ARRAY; the next line then blesses $self as ARRAY. Removing the backslash in the first line would cause $class to get the first argument, and %parameters to get the other arguments converted into a hash, which seems to be more what you want.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://213655]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2015-07-05 15:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls