2 package Moose::Policy::JavaAccessors;
4 use constant attribute_metaclass => 'Moose::Policy::JavaAccessors::Attribute';
6 package Moose::Policy::JavaAccessors::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' . ucfirst($name);
22 elsif ($options->{is} eq 'rw') {
23 $options->{reader} = 'get' . ucfirst($name);
24 $options->{writer} = 'set' . ucfirst($name);
26 delete $options->{is};
38 Moose::Policy::JavaAccessors - BeCause EveryOne Loves CamelCase
44 use Moose::Policy 'Moose::Policy::JavaAccessors';
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 getBaz
54 This meta-policy changes the behavior of Moose's default behavior in
55 regard to accessors to follow Java convention and use CamelCase.
59 This does a very niave conversion to CamelCase, basically it just
60 runs C<ucfirst> on the attribute name. Since I don't use CamelCase
61 (at least not anymore), this is good enough. If you really want to
62 use this, and need a more sophisicated conversion, patches welcome :)
66 All complex software has bugs lurking in it, and this module is no
67 exception. If you find a bug please either email me, or add the bug
72 Stevan Little E<lt>stevan@iinteractive.comE<gt>
74 =head1 COPYRIGHT AND LICENSE
76 Copyright 2006 by Infinity Interactive, Inc.
78 L<http://www.iinteractive.com>
80 This library is free software; you can redistribute it and/or modify
81 it under the same terms as Perl itself.