return $attr->should_coerce;
}
-sub _generate_reader_method { shift->_generate_reader_method_inline(@_) }
-sub _generate_writer_method { shift->_generate_writer_method_inline(@_) }
-sub _generate_accessor_method { shift->_generate_accessor_method_inline(@_) }
-sub _generate_predicate_method { shift->_generate_predicate_method_inline(@_) }
-sub _generate_clearer_method { shift->_generate_clearer_method_inline(@_) }
+sub _instance_is_inlinable {
+ my $self = shift;
+ return $self->associated_attribute->associated_class->instance_metaclass->is_inlinable;
+}
+
+sub _generate_reader_method {
+ my $self = shift;
+ $self->_instance_is_inlinable ? $self->_generate_reader_method_inline(@_)
+ : $self->SUPER::_generate_reader_method(@_);
+}
+
+sub _generate_writer_method {
+ my $self = shift;
+ $self->_instance_is_inlinable ? $self->_generate_writer_method_inline(@_)
+ : $self->SUPER::_generate_writer_method(@_);
+}
+
+sub _generate_accessor_method {
+ my $self = shift;
+ $self->_instance_is_inlinable ? $self->_generate_accessor_method_inline(@_)
+ : $self->SUPER::_generate_accessor_method(@_);
+}
+
+sub _generate_predicate_method {
+ my $self = shift;
+ $self->_instance_is_inlinable ? $self->_generate_predicate_method_inline(@_)
+ : $self->SUPER::_generate_predicate_method(@_);
+}
+
+sub _generate_clearer_method {
+ my $self = shift;
+ $self->_instance_is_inlinable ? $self->_generate_clearer_method_inline(@_)
+ : $self->SUPER::_generate_clearer_method(@_);
+}
sub _inline_pre_body { '' }
sub _inline_post_body { '' }
--- /dev/null
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+my $called;
+{
+ package Foo::Meta::Instance;
+ use Moose::Role;
+
+ sub is_inlinable { 0 }
+
+ after get_slot_value => sub { $called++ };
+}
+
+{
+ package Foo;
+ use Moose;
+ Moose::Util::MetaRole::apply_metaroles(
+ for => __PACKAGE__,
+ class_metaroles => {
+ instance => ['Foo::Meta::Instance'],
+ },
+ );
+
+ has foo => (is => 'ro');
+}
+
+my $foo = Foo->new(foo => 1);
+is($foo->foo, 1, "got the right value");
+is($called, 1, "reader was called");
+
+done_testing;