bump version to 1.12
[gitmo/Moose.git] / lib / Moose / Meta / Attribute.pm
index 818efd1..fd61cba 100644 (file)
@@ -9,9 +9,10 @@ use List::MoreUtils 'any';
 use Try::Tiny;
 use overload     ();
 
-our $VERSION   = '1.08';
+our $VERSION   = '1.12';
 our $AUTHORITY = 'cpan:STEVAN';
 
+use Moose::Deprecated;
 use Moose::Meta::Method::Accessor;
 use Moose::Meta::Method::Delegation;
 use Moose::Util ();
@@ -131,7 +132,10 @@ sub interpolate_class {
 
 # ...
 
-sub illegal_options_for_inheritance { }
+# method-generating options shouldn't be overridden
+sub illegal_options_for_inheritance {
+    qw(reader writer accessor clearer predicate)
+}
 
 # NOTE/TODO
 # This method *must* be able to handle
@@ -150,8 +154,6 @@ sub illegal_options_for_inheritance { }
 sub clone_and_inherit_options {
     my ($self, %options) = @_;
 
-    my %copy = %options;
-
     # NOTE:
     # we may want to extends a Class::MOP::Attribute
     # in which case we need to be able to use the
@@ -163,7 +165,7 @@ sub clone_and_inherit_options {
         ? $self->illegal_options_for_inheritance
         : ();
 
-    my @found_illegal_options = grep { exists $options{$_} ? $_ : undef } @illegal_options;
+    my @found_illegal_options = grep { exists $options{$_} && exists $self->{$_} ? $_ : undef } @illegal_options;
     (scalar @found_illegal_options == 0)
         || $self->throw_error("Illegal inherited options => (" . (join ', ' => @found_illegal_options) . ")", data => \%options);
 
@@ -304,7 +306,12 @@ sub _process_options {
 
         unless ( $options->{type_constraint}->has_coercion ) {
             my $type = $options->{type_constraint}->name;
-            $class->throw_error("You cannot coerce an attribute ($name) unless its type ($type) has a coercion", data => $options);
+
+            Moose::Deprecated::deprecated(
+                feature => 'coerce without coercion',
+                message =>
+                    "You cannot coerce an attribute ($name) unless its type ($type) has a coercion"
+            );
         }
     }
 
@@ -553,6 +560,13 @@ sub _process_accessors {
           . "an accessor"
         );
     }
+    if (!$self->associated_class->has_method($accessor)
+     && $self->associated_class->has_package_symbol('&' . $accessor)) {
+        Carp::cluck(
+            "You are overwriting a locally defined function ($accessor) with "
+          . "an accessor"
+        );
+    }
     $self->SUPER::_process_accessors(@_);
 }
 
@@ -717,7 +731,7 @@ sub _coerce_and_verify {
     return $val unless $self->has_type_constraint;
 
     $val = $self->type_constraint->coerce($val)
-        if $self->should_coerce;
+        if $self->should_coerce && $self->type_constraint->has_coercion;
 
     $self->verify_against_type_constraint($val, instance => $instance);