SPUG:Object property question

Fred Morris m3047 at inwa.net
Mon May 5 21:39:00 CDT 2003


Waaaay too much quoting in this; my apologaeia thus accomplished...

Michael Wolf wrote:
>m3047 at inwa.net (Fred Morris) writes:
>
>> Michael Wolf wrote;
>> >Sanford Morton <smorton at pobox.com> writes:
>> >
>> >[...]
>> >
>> >> sub new {        # constructor     ==> changes and prints first name
>> >>     my $class = shift;
>> >>     my $self = {};
>> >>     $self->_init(@_);
>> >
>> >NOPE!!!! Can't call a member method on an unblessed reference. Well,
>> >you can, but it doesn't do the magic of adding the referent as the
>> >first argument as you assume in the code below. But if you reshuffle
>> >the code, you could do it.
>> >
>> >>     return bless $self, $class;
>> >> }
>> >>
>>
>> Hi Mike.
>>
>> Isn't the problem that they've peeled the class off? (OK, they didn't bless
>> their mess either, but..) Granted their code won't work, but I think the
>> central question concerns overriding, not poor penmanship.
>>
>> How about..
>>
>> sub new ($;$$$ ) {
>>
>>   return SUPER::new( @_ );
>>
>> }
>>
>> or...
>>
>> sub new ($;$$$ ) {
>>
>>     my $class = shift;
>>
>>     return MotherOfAllMesses::new( $class, @_ );
>>
>> }
>
>Yeah, but then it's a function call, not a method.  So what, it's just
>words.  Just semantics.
>
>I don't have time to find it in the books, so I'll scrape some
>(possibly faulty bits) out of the wetware. Perhaps its all the same
>either way -- method or function call. But I foggily remember
>otherwise.
>
>  ** What if SUPER::new doesn't exist? I think the @ISA chain doesn't
>work.
>
>  ** In fact, I'm not even sure the @ISA chain works unless it's
>blessed.

Just in case anybody missed part of this: yes on both counts. In fact,
SUPER::foo() doesn't work although $class->SUPER::foo() as well as
$obj->SUPER::foo() work.. FSQOW. However good to see I'm not the only
wetbrain who made that leap of faith, and specifically: with MOAM::new()
the @ISA chain doesn't work, SUPER::new() is a hopeful ephemeron.

>There's more OO magic about blessing a reference than merely having a
>method (on an object or on a class) call magically unshift in an
>argument (referent or class) as a first argument to unshift off into a
>$this reference or $class scalar.

No, not much more, really. If it's many many lines in the entrails of the
source of the Perl beast, that's tragic not heroic. I confess: I take Perl
at "Interface Value"... to the extent that I take anything at "interface
value"... which is of course taking things at "interface value" since for
the most part I restrain myself from taking things apart for the sheer
mediaeval joy of doing so. I therefore wish to state that although its
behavior is complex, in actuality and for the most part my fiend Perl is
well-behaved and exhibits very little personality. (For anybody who's
confused, that's a Good Thing.)

>And... good examples. They show, very nicely, what really happens with
>SUPER and the unshift/shift of $class.

(I think he meant the examples in the sequel which was a followup to a post
by Colin Meyer...?)

>--
>Michael R. Wolf
>    All mammals learn by playing!
>        MichaelRunningWolf at att.net
>

--

FWM
m3047 at inwa.net





More information about the spug-list mailing list