I think what the OP really wants is what pattern afficionados call a "Factory Method". That factory method shouldn't (re)bless at all but dispatch to the appropriate constructor:
package FooParent; use Carp 'croak'; sub new { # Return either a FooSpecial1 or FooSpecial2 my( $class, %options )= @_; if( $options{ special } == 1 ) { return FooSpecial1->new( %options, special1_param => 'somethin +g' ); } elsif( $options{ special } == 2 ) { return FooSpecial2->new( %options, other_special_param => 'som +ething else' ); } else { croak "Unknown special '$options{special}' requested"; }; }; package FooSpecial1; package FooSpecial2; package main; my $frobnitz = FooParent->new();
In reply to Re^6: Invoking bless triggers "Can't resolve method ..." error
by Corion
in thread Invoking bless triggers "Can't resolve method ..." error
by turkanis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |