More prereq updating. Prep for 0.02 release.
[gitmo/MooseX-SemiAffordanceAccessor.git] / lib / MooseX / Policy / SemiAffordanceAccessor.pm
CommitLineData
a338e27f 1package MooseX::Policy::SemiAffordanceAccessor;
2
3use strict;
4use warnings;
5
9d5dda1c 6our $VERSION = '0.02';
a338e27f 7our $AUTHORITY = 'cpan:DROLSKY';
8
73f3070c 9use constant attribute_metaclass => ## no critic ProhibitConstantPragma
10 'MooseX::Policy::SemiAffordanceAccessor::Attribute';
a338e27f 11
12
73f3070c 13package MooseX::Policy::SemiAffordanceAccessor::Attribute; ## no critic ProhibitMultiplePackages
14
a338e27f 15
16use Moose;
17
18extends 'Moose::Meta::Attribute';
19
20before '_process_options' => sub
21{
22 my $class = shift;
23 my $name = shift;
24 my $options = shift;
25
26 if ( exists $options->{is} &&
27 ! ( exists $options->{reader} || exists $options->{writer} ) )
28 {
29 if ( $options->{is} eq 'ro' )
30 {
31 $options->{reader} = $name;
32 }
33 elsif ( $options->{is} eq 'rw' )
34 {
35 $options->{reader} = $name;
36
37 my $prefix = 'set';
38 if ( $name =~ s/^_// )
39 {
40 $prefix = '_set';
41 }
42
43 $options->{writer} = $prefix . q{_} . $name;
44 }
45
46 delete $options->{is};
47 }
48};
49
50
511;
52
53__END__
54
55=pod
56
57=head1 NAME
58
59MooseX::Policy::SemiAffordanceAccessor - A policy to name accessors foo() and set_foo()
60
61=head1 SYNOPSIS
62
63 use Moose::Policy 'MooseX::Policy::SemiAffordanceAccessor';
64 use Moose;
65
66 # make some attributes
67
68=head1 DESCRIPTION
69
70This class does not provide any methods. Just loading it changes the
71default naming policy for the package so that accessors are separated
72into get and set methods. The get methods have the same name as the
73accessor, while set methods are prefixed with "set_".
74
75If you define an attribute with a leading underscore, then the set
76method will start with "_set_".
77
73f3070c 78If you explicitly set a "reader" or "writer" name when creating an
79attribute, then this policy skips that attribute.
80
a338e27f 81The name "semi-affordance" comes from David Wheeler's Class::Meta
82module.
83
84=head1 AUTHOR
85
86Dave Rolsky, C<< <autarch@urth.org> >>
87
88=head1 BUGS
89
90Please report any bugs or feature requests to
91C<bug-moosex-policy-semiaffordanceaccessor@rt.cpan.org>, or through
92the web interface at L<http://rt.cpan.org>. I will be notified, and
93then you'll automatically be notified of progress on your bug as I
94make changes.
95
96=head1 COPYRIGHT & LICENSE
97
98Copyright 2007 Dave Rolsky, All Rights Reserved.
99
100This program is free software; you can redistribute it and/or modify
101it under the same terms as Perl itself.
102
103=cut