Re: attr initializers (Class::MOP and Moose)
[email protected] (Stevan Little)
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <[email protected]> |
Ricardo, On Feb 6, 2008, at 4:00 PM, Ricardo SIGNES wrote: > * Stevan Little <[email protected]> [2008-02-06T15:34:54] >> On Feb 6, 2008, at 12:18 PM, Ricardo SIGNES wrote: >>> The initializer may be a coderef or a method name (referring to a >>> method >>> on the >>> instance.) It's called like this: >>> >>> $instance->$initializer($value, $name, $callback); >> >> What is $name for again? > > It's the attribute name. This lets you have one initializer for > multiple > attributes. If my contrived example in tests wasn't so contrived > I'd say you > could use it and do this: > > my %mult_for = (foo => 2, bar => 3); > my $multer = sub { $_[3]->($value * $mult_for{$_[2]} }; > has foo => (initializer => $multer); > has bar => (initializer => $multer); > > I am not strongly attached to passing that in. I can see some use for it, but not that much. Perhaps it should be ($value, $callback, $attribute_meta_object) ? This would allow for all sorts of advanced usage, but it could also be safely ignored by those who dont want/need it. - Stevan