On Sun, 21 Aug 2011 22:27:59 +0200 Gunnar Strand <gurra.str...@gmail.com> wrote:
> 1. The above gives me the impression that the accessor method > *replaces*(i.e., renames) the accessor methods. But as I understand > it, after paying > visiting the IRC channel, the accessor methods are also a way to > *bypass*the standard accessor methods. What is not clear is how > accessor write > methods store the value if I have > > "foo => (is => 'rw', writer => 'set_foo')" The 'writer' argument to 'has()' merely generates a method for you to use to set the attribute. It expects an argument. It will also run any constraint checking you've applied to the attribute > > Perhaps the pattern is that if an accessor must store a value.... -SNIP- No, this is overly complicated. 'has()' is just a sugar function to install an accessor into your class. This accessor's behavior (and what methods are generated) are controlled by the arguments given to 'has()'. There really is nothing magical going on here. I promise. > 2. The above example in the manual shows a way to make an attribute > "publicly readable, but privately settable", but I don't see how the > "_set_weight" method can store the weight value? It does seem to say > that "_set_weight" above really updates other values in the object, > and that the value, when read, is derived from those other values. > But if that is the case, shouldn't there be a reader accessor for > weight which derives the value? > > Or is it implied that _set_foo actually stores the value as described > in item 1) above? Again, nothing really magical is happening here. When you use the 'writer' argument in 'has()', you are really telling Moose to install a method in your class, with that name, that will take arguments, and store them in that attribute. > Some light on this would be much appreciated. > > Best Regards, > Gunnar It is really too bad that the YAPCs have happened already this year, because that is when typically the Introduction to Moose class is given (but it's also been known to make a presence at various workshops). It seems like you could really make use of this training and I wholeheartedly recommend it. Barring that, bugging people in IRC probably makes more sense as it is more interactive than doing email. You can also search the archives of this mailing list for answers to more general Moose usage questions. -- Nicholas Perez XMPP/Email: n...@nickandperla.net http://search.cpan.org/~nperez/ http://github.com/nperez