Commit | Line | Data |
a623c113 |
1 | package MooseX::FollowPBP::Role::Attribute; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Moose::Role; |
7 | |
73198536 |
8 | before _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 | |
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 | |