allow immutable options to override file and line
[gitmo/Moose.git] / lib / Class / MOP / Attribute.pm
index 6b7a24f..d16d66f 100644 (file)
@@ -10,8 +10,6 @@ use Carp         'confess';
 use Scalar::Util 'blessed', 'weaken';
 use Try::Tiny;
 
-our $AUTHORITY = 'cpan:STEVAN';
-
 use base 'Class::MOP::Object', 'Class::MOP::Mixin::AttributeCore';
 
 # NOTE: (meta-circularity)
@@ -380,7 +378,7 @@ sub _process_accessors {
         my $method;
         try {
             if ( $method_ctx ) {
-                my $desc = "accessor $accessor";
+                my $desc = "accessor " . $self->associated_class->name . "::$accessor";
                 if ( $accessor ne $self->name ) {
                     $desc .= " of attribute " . $self->name;
                 }
@@ -619,8 +617,31 @@ attribute initialization use the writer:
       )
   );
 
-Your writer will need to examine C<@_> and determine under which
-context it is being called.
+Your writer (actually, a wrapper around the writer, using
+L<method modifications|Moose::Manual::MethodModifiers>) will need to examine
+C<@_> and determine under which
+context it is being called:
+
+  around 'some_attr' => sub {
+      my $orig = shift;
+      my $self = shift;
+      # $value is not defined if being called as a reader
+      # $setter and $attr are only defined if being called as an initializer
+      my ($value, $setter, $attr) = @_;
+
+      # the reader behaves normally
+      return $self->$orig if not @_;
+
+      # mutate $value as desired
+      # $value = <something($value);
+
+      # if called as an initializer, set the value and we're done
+      return $setter->($row) if $setter;
+
+      # otherwise, call the real writer with the new value
+      $self->$orig($row);
+  };
+
 
 =back