Changelog tweaks for 0.94
[gitmo/Class-MOP.git] / lib / Class / MOP / Attribute.pm
index e6e9b77..28e41cd 100644 (file)
@@ -9,7 +9,7 @@ use Class::MOP::Method::Accessor;
 use Carp         'confess';
 use Scalar::Util 'blessed', 'weaken';
 
-our $VERSION   = '0.83';
+our $VERSION   = '0.93';
 $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
@@ -32,7 +32,7 @@ sub new {
 
     my $name = $options{name};
 
-    (defined $name && $name)
+    (defined $name)
         || confess "You must provide a name for the attribute";
 
     $options{init_arg} = $name
@@ -57,6 +57,10 @@ sub new {
 
 sub _new {
     my $class = shift;
+
+    return Class::MOP::Class->initialize($class)->new_object(@_)
+        if $class ne __PACKAGE__;
+
     my $options = @_ == 1 ? $_[0] : {@_};
 
     bless {
@@ -248,7 +252,9 @@ sub get_write_method_ref {
 }
 
 sub is_default_a_coderef {
-    ('CODE' eq ref($_[0]->{'default'}))
+    my ($value) = $_[0]->{'default'};
+    return unless ref($value);
+    return ref($value) eq 'CODE' || (blessed($value) && $value->isa('Class::MOP::Method'));
 }
 
 sub default {
@@ -299,7 +305,10 @@ sub set_initial_value {
     );
 }
 
-sub set_value {
+sub set_value { shift->set_raw_value(@_) }
+sub get_value { shift->get_raw_value(@_) }
+
+sub set_raw_value {
     my ($self, $instance, $value) = @_;
 
     Class::MOP::Class->initialize(ref($instance))
@@ -307,7 +316,7 @@ sub set_value {
                      ->set_slot_value($instance, $self->name, $value);
 }
 
-sub get_value {
+sub get_raw_value {
     my ($self, $instance) = @_;
 
     Class::MOP::Class->initialize(ref($instance))
@@ -335,12 +344,6 @@ sub clear_value {
 
 sub accessor_metaclass { 'Class::MOP::Method::Accessor' }
 
-sub process_accessors {
-    Carp::cluck('The process_accessors method has been made private.'
-        . " The public version is deprecated and will be removed in a future release.\n");
-    shift->_process_accessors(@_);
-}
-
 sub _process_accessors {
     my ($self, $type, $accessor, $generate_as_inline_methods) = @_;
 
@@ -591,7 +594,7 @@ twice the given value.
   Class::MOP::Attribute->new(
       'doubled' => (
           initializer => sub {
-              my ( $instance, $value, $set ) = @_;
+              my ( $self, $value, $set, $attr ) = @_;
               $set->( $value * 2 );
           },
       )
@@ -827,6 +830,12 @@ It's unlikely that you'll need to call this method yourself.
 Sets the value without going through the accessor. Note that this
 works even with read-only attributes.
 
+=item B<< $attr->set_raw_value($instance, $value) >>
+
+Sets the value with no side effects such as a trigger.
+
+This doesn't actually apply to Class::MOP attributes, only to subclasses.
+
 =item B<< $attr->set_initial_value($instance, $value) >>
 
 Sets the value without going through the accessor. This method is only
@@ -837,6 +846,12 @@ called when the instance is first being initialized.
 Returns the value without going through the accessor. Note that this
 works even with write-only accessors.
 
+=item B<< $sttr->get_raw_value($instance) >>
+
+Returns the value without any side effects such as lazy attributes.
+
+Doesn't actually apply to Class::MOP attributes, only to subclasses.
+
 =item B<< $attr->has_value($instance) >>
 
 Return a boolean indicating whether the attribute has been set in