in reply to Perl Factory Method Pattern?
To answer the questions you actually asked, in reverse order:
- Yes, this is the way to rebless into a new class.
- The way you've coded the "new" method, it calls _init using a method call on $self. It needs to be blessed for this to work. You could change this to a simple subroutine call: _init( $self ), and not bother with the first blessing.
What you've coded will work, and most of it is fine; but there are a couple of things I dislike about the class structure you've used:
- First, you have two _init methods, which do different things: one is a factory method; the other is a genuine instance initialisation.
- Second, your base class, ProcInfo, has two roles: first, it's a factory; second, it's a ProcInfo thingy.
In Section
Seekers of Perl Wisdom