Re: chained accessors

[email protected] (Stevan Little)
Newsgroups perl.moose
Message-ID <[email protected]>
Carl,

On Nov 27, 2006, at 5:05 AM, Carl Franks wrote:
> I've noticed from Devel::Cover results, that only
> generate_accessor_method() is being called.
>
> Do you know, under what circumstances would generate_writer_method 
> () be called?

The "is" option is basically a kind of macro for the "accessor" and  
"reader" options from Class::MOP's attributes.

This:

has 'foo' => (is => 'rw');

ends up "expanding" into this:

has 'foo' => (accessor => 'foo');

and this:

has 'bar' => (is => 'ro');

ends up "expanding" into this:

has 'bar' => (reader => 'bar');

Of course you can manually set these things in Moose as well, like so:

has 'foo' => (
     reader => 'getFoo',
     writer => 'setFoo',
);

So, while you are only seeing generate_accessor_method() called, I  
would keep generate_writer_method() around for completeness because  
you might need it at some point.

- Steve
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.