in reply to changing moose object classes on the go

Pretty much the same sort of question I asked a while ago here. The quick answer is as follows:

package Dog; use Moose; has 'breed' => ( is => 'ro',isa=>'String'); has 'color' => ( is => 'rw', isa=>'String'); sub BUILD { my $self =shift; my $class = "Dog::" . $self->breed(); $class->meta->rebless_instance($self); } 1;
and somewhere in user space:
| handwaving here.. use Dog; # updated this on 2013-04-24, error in original code my $dog = Dog->new(breed=>'Poodle'); | |


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Replies are listed 'Best First'.
Re^2: changing moose object classes on the go
by tomgracey (Scribe) on Apr 24, 2013 at 09:55 UTC

    Hi Peter

    Realise its a while ago and I forgot to thank you for this - basically ->rebless_instance($self) was the answer. Thanks enormously!