SPUG: method call during object construction

Umar Cheema umar at drizzle.com
Wed Feb 15 15:06:13 PST 2006


I was hoping to make this work:

my $obj = Class->new('class_name')->change_name('new_class_name');
$obj->do_other_things();
....

But after the constructor call $obj simply holds the value returned by the 
'change_name' method.

Of course the following works just fine:

my $obj = Class->new('class_name');
$obj->change_name('new_name');
$obj->do_other_things();
...

Can someone explain what is going on with the first way of calling a 
method during construction? Is this something we're not suppose to do or 
am I just seeing weird perl behavior for some other reason?

Thanks,
Umar



More information about the spug-list mailing list