On Mon, Feb 16, 2009 at 5:51 PM, Chris Prather <perig...@gmail.com> wrote: > You can access the attr through the mop as well but I don't have the docs in > front of me. Check the attr docs a bit more the answer should be there. > > On Feb 16, 2009 5:05 PM, "Chad Davis" <chad.a.da...@gmail.com> wrote: > > Chris, > > Thanks for reminding me to look in Class::MOP. I had just checked > Moose and looked at 'writer', but didn't realize you could give it, > and 'accessor', a named sub as well. > > I think I was looking for something that's a compromise between an > iniatializer and 'around'. Your code works for me, though, I was > hoping to find a way to do it without directly accessing > $self->{myattr}, as I didn't want to assume anything about the > implementation (e.g. in Bioperl $self->attr() accesses $self->{_attr} > often). Otherwise I might have just done: > > has 'myattr' => ( is=>'rw', isa=>'Str', > > trigger => sub { (shift)->{myattr} =~ s/\s//g }, > ); > which also works when myattr is set via the constructor. > > I think I'll stick with coerce to do this for now, as Dave suggested. >
Okay I'm back near a real computer: $self->get_attribute('myattr')->set_value ($self, $value); is the MOP way of setting the value. Which that will work in your trigger or in a custom accessor method. -Chris