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 | |
7e7ad65a |
13 | if ( exists $options->{is} |
14 | && !( exists $options->{reader} || exists $options->{writer} ) |
15 | && $options->{is} ne 'bare' ) { |
a623c113 |
16 | my $get; |
17 | my $set; |
18 | |
73198536 |
19 | if ( $name =~ s/^_// ) { |
a623c113 |
20 | $get = '_get_'; |
21 | $set = '_set_'; |
22 | } |
73198536 |
23 | else { |
a623c113 |
24 | $get = 'get_'; |
25 | $set = 'set_'; |
26 | } |
27 | |
28 | $options->{reader} = $get . $name; |
29 | |
73198536 |
30 | if ( $options->{is} eq 'rw' ) { |
a623c113 |
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 | |
00ccc022 |
44 | Moose::Util::MetaRole::apply_metaclass_roles( |
45 | for => $p{for_class}, |
46 | class_metaroles => { |
47 | attribute => ['MooseX::FollowPBP::Role::Attribute'], |
48 | }, |
49 | ); |
a623c113 |
50 | |
51 | =head1 DESCRIPTION |
52 | |
53 | This role applies a method modifier to the C<_process_options()> |
54 | method, and tweaks the reader and writer parameters so that they |
55 | follow the style recommended in I<Perl Best Practices>. |
56 | |
57 | =cut |
58 | |