> The typical constructor would then be reduced to:
>
> package MyClass;
>
> sub new { bless {}, @_ }
>
> with initialization handled in a separate C<SETUP> routine:
>
> sub SETUP {
> my ($self, @ctor_data) = @_;
> # initialization of object referred to by $self occurs here
> }
Hmmm. I'm not sure if I like this. I like the *idea* a lot, but I must
say that I think I quite like RFC 171's approach better.
The big problem with this is that what you're doing is having the object
make a call to new(), which is intercepted by Perl because it sees the
bless() going on, and then SETUP() is called. This is lots of
action-at-a-distance hidden stuff.
I'd rather this be done in the reverse way:
package MyClass;
sub new { SETUP(@_) }
sub SETUP {
bless { }, @_;
my ($self, @ctor_data) = @_;
# initialization of object referred to by $self occurs here
}
That is, new() is just a synonym for SETUP. You could still easily chain
together SETUP's, just by specifying that something isa something else.
This is much clearer, and now you simply initialize something by calling
SETUP, instead of calling bless. The end result is the same, though. You
just call SETUP, not bless, if you have to create an object. This is no
different from calling DESTROY manually if you really need to.
Intercepting bless calls hides way too much for my tastes, and doesn't
add anything the above doesn't handle, AFAICT.
-Nate