dzilize
[gitmo/MooseX-SemiAffordanceAccessor.git] / lib / MooseX / SemiAffordanceAccessor / Role / Attribute.pm
1 package MooseX::SemiAffordanceAccessor::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         if ( $options->{is} eq 'ro' ) {
16             $options->{reader} = $name;
17             delete $options->{is};
18         }
19         elsif ( $options->{is} eq 'rw' ) {
20             $options->{reader} = $name;
21
22             my $prefix = 'set';
23             if ( $name =~ s/^_// ) {
24                 $prefix = '_set';
25             }
26
27             $options->{writer} = $prefix . q{_} . $name;
28             delete $options->{is};
29         }
30     }
31 };
32
33 no Moose::Role;
34
35 1;
36
37 =head1 SYNOPSIS
38
39   Moose::Util::MetaRole::apply_metaclass_roles(
40       for_class => $p{for_class},
41       attribute_metaclass_roles =>
42           ['MooseX::SemiAffordanceAccessor::Role::Attribute'],
43   );
44
45 =head1 DESCRIPTION
46
47 This role applies a method modifier to the C<_process_options()>
48 method, and tweaks the reader and writer parameters so that they
49 follow the semi-affordance naming style.
50
51 =cut
52