SPUG:Object property question
Michael R. Wolf
MichaelRunningWolf at att.net
Mon May 5 01:44:30 CDT 2003
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.
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.
And... good examples. They show, very nicely, what really happens with
SUPER and the unshift/shift of $class.
--
Michael R. Wolf
All mammals learn by playing!
MichaelRunningWolf at att.net
More information about the spug-list
mailing list