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