JavaAccessors forPeopleWhoLikeJava
[gitmo/Moose-Policy.git] / lib / Moose / Policy / JavaAccessors.pm
diff --git a/lib/Moose/Policy/JavaAccessors.pm b/lib/Moose/Policy/JavaAccessors.pm
new file mode 100644 (file)
index 0000000..fea56dd
--- /dev/null
@@ -0,0 +1,36 @@
+
+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__
+
+=pod
+
+=cut