in reply to OO Perl: calling a constructor within a class

Many of my objects have a structure that looks like this:

package MyObject; sub new { my $thing = shift; my $class = ref $thing || $thing; my $self = bless {}, $class; return $self->init(@_); } sub init { my $self = shift; # do initialisation stuff with the values in @_ return $self; }

Does that help you at all?

Update: Actually I tend to agree with both tilly and merlyn on the class/instance method divide. The $class = ref $thing || $thing idiom just seems to be hard-wired into my conciousness thru reading in so many books. I have to think twice to not use it. Generally my new method will be a class method and I'll only create an instance method version in the rare cases when I need a copy constructor.

--
<http://www.dave.org.uk>

"The first rule of Perl club is you don't talk about Perl club."