note
blue_cowdawg
<ul><ul><i>
(I guess what I'm really asking is - is there a way to change the class of an object that already exists under Moose? Or perhaps this is not the done thing?)
</i></ul></ul>
<p>
Pretty much the same sort of question I asked a while ago [1020336|here]. The quick answer is as follows:
<code>
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;
</code>
and somewhere in user space:
<code>
| handwaving here..
use Dog;
# updated this on 2013-04-24, error in original code
my $dog = Dog->new(breed=>'Poodle');
|
|
</code>
</p>
<div class="pmsig"><div class="pmsig-72516">
<hr>
<font size="-2">
Peter L. Berghold -- Unix Professional<br>
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg<br>
</font>
</div></div>
1024349
1024349