add test for is => 'bare'
[gitmo/MooseX-SemiAffordanceAccessor.git] / lib / MooseX / SemiAffordanceAccessor / Role / Attribute.pm
CommitLineData
b95d9f9b 1package MooseX::SemiAffordanceAccessor::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 if ( $options->{is} eq 'ro' )
19 {
20 $options->{reader} = $name;
21 }
22 elsif ( $options->{is} eq 'rw' )
23 {
24 $options->{reader} = $name;
25
26 my $prefix = 'set';
27 if ( $name =~ s/^_// )
28 {
29 $prefix = '_set';
30 }
31
32 $options->{writer} = $prefix . q{_} . $name;
33 }
34
35 delete $options->{is};
36 }
37};
38
39no Moose::Role;
40
411;
58828d60 42
43=head1 NAME
44
45MooseX::SemiAffordanceAccessor::Role::Attribute - Names accessors in a semi-affordance style
46
47=head1 SYNOPSIS
48
49 Moose::Util::MetaRole::apply_metaclass_roles
50 ( for_class => $p{for_class},
51 attribute_metaclass_roles =>
52 ['MooseX::SemiAffordanceAccessor::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 semi-affordance naming style.
60
61=head1 AUTHOR
62
63Dave Rolsky, C<< <autarch@urth.org> >>
64
65=head1 COPYRIGHT & LICENSE
66
67Copyright 2007-2008 Dave Rolsky, All Rights Reserved.
68
69This program is free software; you can redistribute it and/or modify
70it under the same terms as Perl itself.
71
72=cut
73