Tidy code
[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         my $get;
16         my $set;
17
18         if ( $name =~ s/^_// ) {
19             $get = '_get_';
20             $set = '_set_';
21         }
22         else {
23             $get = 'get_';
24             $set = 'set_';
25         }
26
27         $options->{reader} = $get . $name;
28
29         if ( $options->{is} eq 'rw' ) {
30             $options->{writer} = $set . $name;
31         }
32
33         delete $options->{is};
34     }
35 };
36
37 no Moose::Role;
38
39 1;
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
51 This role applies a method modifier to the C<_process_options()>
52 method, and tweaks the reader and writer parameters so that they
53 follow the style recommended in I<Perl Best Practices>.
54
55 =cut
56