1 package MooseX::Policy::SemiAffordanceAccessor;
7 our $AUTHORITY = 'cpan:DROLSKY';
9 use constant attribute_metaclass => ## no critic ProhibitConstantPragma
10 'MooseX::Policy::SemiAffordanceAccessor::Attribute';
13 package MooseX::Policy::SemiAffordanceAccessor::Attribute; ## no critic ProhibitMultiplePackages
18 extends 'Moose::Meta::Attribute';
20 before '_process_options' => sub
26 if ( exists $options->{is} &&
27 ! ( exists $options->{reader} || exists $options->{writer} ) )
29 if ( $options->{is} eq 'ro' )
31 $options->{reader} = $name;
33 elsif ( $options->{is} eq 'rw' )
35 $options->{reader} = $name;
38 if ( $name =~ s/^_// )
43 $options->{writer} = $prefix . q{_} . $name;
46 delete $options->{is};
59 MooseX::Policy::SemiAffordanceAccessor - A policy to name accessors foo() and set_foo()
63 use Moose::Policy 'MooseX::Policy::SemiAffordanceAccessor';
66 # make some attributes
70 This class does not provide any methods. Just loading it changes the
71 default naming policy for the package so that accessors are separated
72 into get and set methods. The get methods have the same name as the
73 accessor, while set methods are prefixed with "set_".
75 If you define an attribute with a leading underscore, then the set
76 method will start with "_set_".
78 If you explicitly set a "reader" or "writer" name when creating an
79 attribute, then this policy skips that attribute.
81 The name "semi-affordance" comes from David Wheeler's Class::Meta
86 Dave Rolsky, C<< <autarch@urth.org> >>
90 Please report any bugs or feature requests to
91 C<bug-moosex-policy-semiaffordanceaccessor@rt.cpan.org>, or through
92 the web interface at L<http://rt.cpan.org>. I will be notified, and
93 then you'll automatically be notified of progress on your bug as I
96 =head1 COPYRIGHT & LICENSE
98 Copyright 2007 Dave Rolsky, All Rights Reserved.
100 This program is free software; you can redistribute it and/or modify
101 it under the same terms as Perl itself.