Re: make_immutable bug?
[email protected] ("woosley. xu.")
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <CAG6tKJOYx8svBXbWNH3a3jBiuseh9B50qbX21voSE88YX2AJ3w@mail.gmail.com> |
2011/12/2 Jesse Luehrs <[email protected]> > On Fri, Dec 02, 2011 at 09:45:51AM +0800, woosley. xu. wrote: > > but I think I got your point. So basically even if I run > > meta->make_immutable on an constructed object, it is applied to the whole > > __CLASS__, not just the object. > > Right. > > > What I want to do is to 'with' different Roles depending on the user > > arguments passed to 'new' constructor, and then make the object > immutable. > > is that possible? > > Yes, this is possible. See MooseX::Traits, which does this sort of thing > for you. > > Thanks, MooseX::Traits looks like what I want. Only on problem, it can not be used in 'BUILDARGS' #!/usr/bin/perl -w package A; { use Moose::Role; } package Class; { use Moose; with 'MooseX::Traits'; around 'BUILDARGS' => sub { my ($orig, $class, @args) = @_; return $class->with_traits("A")->$orig(); } } package main; my $c = Class->new(); print $c->does('A'); ## get 0 here > -doy > -- woosley.xu. http://twitter.com/redicaps