Re: Moose/mouse r/o variables
[email protected] (Matt S Trout)
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <[email protected]> |
On 30/03/11 20:20, Chris Weyl wrote: > On Mon, Mar 28, 2011 at 6:22 AM, Stevan Little< > [email protected]> wrote: > >> >> On Mar 28, 2011, at 8:28 AM, Peter Gordon wrote: >> >>> I have a small class, where I would like the variables to be read only >>> by external calls, but rw for internal access. >> >> has 'foo' => ( is => 'ro', writer => '_set_foo', ... ); >> >> Is the more common method for this. > > > On a related note, I actually found myself using that construction > frequently enough that I finally put together an attribute trait to take "is > => 'rwp'" (read-write-private) which then sets "is => 'ro', writer => > '_$name'". It's on the CPAN at MooseX::AttributeShortcuts... The next > version is likely to be parameterizable, so '_set_$name' could be the > generated writer name. _set_$name is the convention pretty much everywhere I see it done so that should be the default. It'd also be nice if you could steal Moo's is => 'lazy' shortcut since I'd like that to work for people doing Moose stuff as well in order to be able to de-experimental it since it's rather nicer than lazy_build