Get inline slot access snippets from attr, not direct from meta-instance
[gitmo/Moose.git] / lib / Moose / Meta / Attribute.pm
index fd61cba..640d1cc 100644 (file)
@@ -9,7 +9,7 @@ use List::MoreUtils 'any';
 use Try::Tiny;
 use overload     ();
 
-our $VERSION   = '1.12';
+our $VERSION   = '1.14';
 our $AUTHORITY = 'cpan:STEVAN';
 
 use Moose::Deprecated;
@@ -577,6 +577,22 @@ sub remove_accessors {
     return;
 }
 
+sub inline_set {
+    my $self = shift;
+    my ( $instance, $value ) = @_;
+
+    my $mi = $self->associated_class->get_meta_instance;
+
+    my $code
+        = $mi->inline_set_slot_value( $instance, $self->slots, $value ) . ";";
+    $code
+        .= $mi->inline_weaken_slot_value( $instance, $self->slots, $value )
+        . ";"
+        if $self->is_weak_ref;
+
+    return $code;
+}
+
 sub install_delegation {
     my $self = shift;
 
@@ -836,7 +852,7 @@ object which does the named role.
 =item * coerce => $bool
 
 This option is only valid for objects with a type constraint
-(C<isa>). If this is true, then coercions will be applied whenever
+(C<isa>) that defined a coercion. If this is true, then coercions will be applied whenever
 this attribute is set.
 
 You can make both this and the C<weak_ref> option true.
@@ -963,6 +979,12 @@ methods is almost always an error.)
 
 This method overrides the parent to also remove delegation methods.
 
+=item B<< $attr->inline_set($instance_var, $value_var) >>
+
+This method return a code snippet suitable for inlining the relevant
+operation. It expect strings containing variable names to be used in the
+inlining, like C<'$self'> or C<'$_[1]'>.
+
 =item B<< $attr->install_delegation >>
 
 This method adds its delegation methods to the attribute's associated