2 package Moose::Policy::FollowPBP;
4 use constant attribute_metaclass => 'Moose::Policy::FollowPBP::Attribute';
6 package Moose::Policy::FollowPBP::Attribute;
9 extends 'Moose::Meta::Attribute';
11 before '_process_options' => sub {
12 my ($class, $name, $options) = @_;
14 # If is has been specified, and
15 # we don't have a reader or writer
16 # Of couse this is an odd case, but
17 # we better test for it anyway.
18 if (exists $options->{is} && !(exists $options->{reader} || exists $options->{writer})) {
19 if ($options->{is} eq 'ro') {
20 $options->{reader} = 'get_' . $name;
22 elsif ($options->{is} eq 'rw') {
23 $options->{reader} = 'get_' . $name;
24 $options->{writer} = 'set_' . $name;
26 delete $options->{is};
38 Moose::Policy::FollowPBP - Follow the recomendations in Perl Best Practices
44 use Moose::Policy 'Moose::Policy::FollowPBP';
47 has 'bar' => (is => 'rw', default => 'Foo::bar');
48 has 'baz' => (is => 'ro', default => 'Foo::baz');
50 # Foo now has (get, set)_bar methods as well as get_baz
54 This meta-policy changes the behavior of Moose's default behavior in
55 regard to accessors to follow the recomdnations found in Damian
56 Conway's book Perl Best Practices.
60 All complex software has bugs lurking in it, and this module is no
61 exception. If you find a bug please either email me, or add the bug
66 Stevan Little E<lt>stevan@iinteractive.comE<gt>
68 =head1 COPYRIGHT AND LICENSE
70 Copyright 2006 by Infinity Interactive, Inc.
72 L<http://www.iinteractive.com>
74 This library is free software; you can redistribute it and/or modify
75 it under the same terms as Perl itself.