Fix repo type
[gitmo/MooseX-FollowPBP.git] / lib / MooseX / FollowPBP / Role / Attribute.pm
CommitLineData
a623c113 1package MooseX::FollowPBP::Role::Attribute;
2
3use strict;
4use warnings;
5
6use Moose::Role;
7
8
9before '_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
43no Moose::Role;
44
451;
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
57This role applies a method modifier to the C<_process_options()>
58method, and tweaks the reader and writer parameters so that they
59follow the style recommended in I<Perl Best Practices>.
60
61=cut
62