SPUG:Object property question

Fred Morris m3047 at inwa.net
Fri May 2 19:24:08 CDT 2003

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( @_ );



sub new ($;$$$ ) {

    my $class = shift;

    return MotherOfAllMesses::new( $class, @_ );




Works for me. I think, anyway. I've done things like this, recently, even.


(It's more interesting when the MOAM takes different params to the default
new than the child, so you peel those off and pass them in order,
appropriately spiced.)


m3047 at inwa.net

More information about the spug-list mailing list