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