Tidy code
[gitmo/MooseX-FollowPBP.git] / lib / MooseX / FollowPBP / Role / Attribute.pm
CommitLineData
a623c113 1package MooseX::FollowPBP::Role::Attribute;
2
3use strict;
4use warnings;
5
6use Moose::Role;
7
73198536 8before _process_options => sub {
a623c113 9 my $class = shift;
10 my $name = shift;
11 my $options = shift;
12
73198536 13 if ( exists $options->{is}
14 && !( exists $options->{reader} || exists $options->{writer} ) ) {
a623c113 15 my $get;
16 my $set;
17
73198536 18 if ( $name =~ s/^_// ) {
a623c113 19 $get = '_get_';
20 $set = '_set_';
21 }
73198536 22 else {
a623c113 23 $get = 'get_';
24 $set = 'set_';
25 }
26
27 $options->{reader} = $get . $name;
28
73198536 29 if ( $options->{is} eq 'rw' ) {
a623c113 30 $options->{writer} = $set . $name;
31 }
32
33 delete $options->{is};
34 }
35};
36
37no Moose::Role;
38
391;
40
41=head1 SYNOPSIS
42
43 Moose::Util::MetaRole::apply_metaclass_roles
44 ( for_class => $p{for_class},
45 attribute_metaclass_roles =>
46 ['MooseX::FollowPBP::Role::Attribute'],
47 );
48
49=head1 DESCRIPTION
50
51This role applies a method modifier to the C<_process_options()>
52method, and tweaks the reader and writer parameters so that they
53follow the style recommended in I<Perl Best Practices>.
54
55=cut
56