Moose::Policy::JavaAccessors - BeCause EveryOne Loves CamelCase


Moose-Policy documentation Contained in the Moose-Policy distribution.

Index


Code Index:

NAME

Top

Moose::Policy::JavaAccessors - BeCause EveryOne Loves CamelCase

SYNOPSIS

Top

  package Foo;

  use Moose::Policy 'Moose::Policy::JavaAccessors';
  use Moose;

  has 'bar' => (is => 'rw', default => 'Foo::bar');
  has 'baz' => (is => 'ro', default => 'Foo::baz');

  # Foo now has (get, set)Bar methods as well as getBaz

DEPRECATION NOTICE

Top

Moose::Policy is deprecated.

DESCRIPTION

Top

This meta-policy changes the behavior of Moose's default behavior in regard to accessors to follow Java convention and use CamelCase.

CAVEAT

Top

This does a very niave conversion to CamelCase, basically it just runs ucfirst on the attribute name. Since I don't use CamelCase (at least not anymore), this is good enough. If you really want to use this, and need a more sophisicated conversion, patches welcome :)

BUGS

Top

All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.

AUTHOR

Top

Stevan Little <stevan@iinteractive.com>

COPYRIGHT AND LICENSE

Top


Moose-Policy documentation Contained in the Moose-Policy distribution.

package Moose::Policy::JavaAccessors;

use constant attribute_metaclass => 'Moose::Policy::JavaAccessors::Attribute';

package Moose::Policy::JavaAccessors::Attribute;
use Moose;

extends 'Moose::Meta::Attribute';

before '_process_options' => sub {
    my ($class, $name, $options) = @_;
    # NOTE:
    # If is has been specified, and 
    # we don't have a reader or writer
    # Of couse this is an odd case, but
    # we better test for it anyway.
    if (exists $options->{is} && !(exists $options->{reader} || exists $options->{writer})) {
        if ($options->{is} eq 'ro') {
            $options->{reader} = 'get' . ucfirst($name);
        }
        elsif ($options->{is} eq 'rw') {
            $options->{reader} = 'get' . ucfirst($name);
            $options->{writer} = 'set' . ucfirst($name);
        }
        delete $options->{is};
    }
};

1;

__END__