MooseX::PrivateSetters - Names your accessors foo() and _set_foo()
use Moose; use MooseX::PrivateSetters; # make some attributes has 'foo' => ( is => 'rw' ); ... package main; sub bar { $self = shift; $self->_set_foo(1) unless $self->foo }
This module does not provide any methods. Simply loading it changes the default naming policy for the loading class so that accessors are separated into get and set methods. The get methods have the same name as the accessor, while set methods are prefixed with _set_.
_set_
If you declare an attribute with a leading underscore, then the set method will start with "_set" (i.e. has '_foo' will get a setter called _set_foo. Note that if you have attributes foo and _foo, they will both get a setter called _set_foo, so don't do that.
has '_foo'
_set_foo
foo
_foo
If you explicitly set a reader or writer name when creating an attribute, then that attribute's naming scheme is left unchanged.
reader
writer
Load order of this module is important. It must be used after Moose.
use
There are a number of similar modules on the CPAN.
The original. A single mutator method is generated with the same name as the attribute itself.
Changes the parsing of the is clause, making new options available. For example,
is
has baz => ( is => 'rpwp', # private reader, private writer
gets you _get_baz() and _set_baz.
_get_baz()
_set_baz
Names accessors in the style recommended by Perl Best Practices: get_size and set_size.
get_size
set_size
Has separate methods for getting and setting. The getter has the same name as the attribute, and the setter is prefixed with set_.
set_
brian greenfield <briang@cpan.org>
<briang@cpan.org>
Please report any bugs or feature requests to bug-moosex-privatesetters@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-moosex-privatesetters@rt.cpan.org
Copyright 2010 brian greenfield
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install MooseX::PrivateSetters, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::PrivateSetters
CPAN shell
perl -MCPAN -e shell install MooseX::PrivateSetters
For more information on module installation, please visit the detailed CPAN module installation guide.