Commit | Line | Data |
b95d9f9b |
1 | package MooseX::SemiAffordanceAccessor::Role::Attribute; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Moose::Role; |
7 | |
f227d76f |
8 | before '_process_options' => sub { |
b95d9f9b |
9 | my $class = shift; |
10 | my $name = shift; |
11 | my $options = shift; |
12 | |
f227d76f |
13 | if ( exists $options->{is} |
14 | && !( exists $options->{reader} || exists $options->{writer} ) ) { |
15 | if ( $options->{is} eq 'ro' ) { |
b95d9f9b |
16 | $options->{reader} = $name; |
883845e4 |
17 | delete $options->{is}; |
b95d9f9b |
18 | } |
f227d76f |
19 | elsif ( $options->{is} eq 'rw' ) { |
b95d9f9b |
20 | $options->{reader} = $name; |
21 | |
22 | my $prefix = 'set'; |
f227d76f |
23 | if ( $name =~ s/^_// ) { |
b95d9f9b |
24 | $prefix = '_set'; |
25 | } |
26 | |
27 | $options->{writer} = $prefix . q{_} . $name; |
883845e4 |
28 | delete $options->{is}; |
b95d9f9b |
29 | } |
b95d9f9b |
30 | } |
31 | }; |
32 | |
33 | no Moose::Role; |
34 | |
35 | 1; |
58828d60 |
36 | |
37 | =head1 NAME |
38 | |
39 | MooseX::SemiAffordanceAccessor::Role::Attribute - Names accessors in a semi-affordance style |
40 | |
41 | =head1 SYNOPSIS |
42 | |
43 | Moose::Util::MetaRole::apply_metaclass_roles |
44 | ( for_class => $p{for_class}, |
45 | attribute_metaclass_roles => |
46 | ['MooseX::SemiAffordanceAccessor::Role::Attribute'], |
47 | ); |
48 | |
49 | =head1 DESCRIPTION |
50 | |
51 | This role applies a method modifier to the C<_process_options()> |
52 | method, and tweaks the reader and writer parameters so that they |
53 | follow the semi-affordance naming style. |
54 | |
55 | =head1 AUTHOR |
56 | |
57 | Dave Rolsky, C<< <autarch@urth.org> >> |
58 | |
59 | =head1 COPYRIGHT & LICENSE |
60 | |
61 | Copyright 2007-2008 Dave Rolsky, All Rights Reserved. |
62 | |
63 | This program is free software; you can redistribute it and/or modify |
64 | it under the same terms as Perl itself. |
65 | |
66 | =cut |
67 | |