return $self->associated_class->get_method($reader);
}
else {
- return sub { $self->get_value(@_) };
+ my $code = sub { $self->get_value(@_) };
+ if (my $class = $self->associated_class) {
+ return $class->method_metaclass->wrap(
+ $code,
+ package_name => $class->name,
+ name => '__ANON__'
+ );
+ }
+ else {
+ return $code;
+ }
}
}
return $self->associated_class->get_method($writer);
}
else {
- return sub { $self->set_value(@_) };
+ my $code = sub { $self->set_value(@_) };
+ if (my $class = $self->associated_class) {
+ return $class->method_metaclass->wrap(
+ $code,
+ package_name => $class->name,
+ name => '__ANON__'
+ );
+ }
+ else {
+ return $code;
+ }
}
}
use Scalar::Util 'reftype', 'blessed';
-use Test::More tests => 97;
+use Test::More tests => 101;
use Test::Exception;
BEGIN {
ok(!$attr->has_default, '... $attr does not have an default');
ok(!$attr->has_builder, '... $attr does not have a builder');
+ {
+ my $reader = $attr->get_read_method_ref;
+ my $writer = $attr->get_write_method_ref;
+
+ ok(!blessed($reader), '... it is a plain old sub');
+ ok(!blessed($writer), '... it is a plain old sub');
+
+ is(reftype($reader), 'CODE', '... it is a plain old sub');
+ is(reftype($writer), 'CODE', '... it is a plain old sub');
+ }
+
my $class = Class::MOP::Class->initialize('Foo');
isa_ok($class, 'Class::MOP::Class');
my $reader = $attr->get_read_method_ref;
my $writer = $attr->get_write_method_ref;
- ok(!blessed($reader), '... it is a plain old sub');
- ok(!blessed($writer), '... it is a plain old sub');
+ ok(blessed($reader), '... it is a plain old sub');
+ ok(blessed($writer), '... it is a plain old sub');
- is(reftype($reader), 'CODE', '... it is a plain old sub');
- is(reftype($writer), 'CODE', '... it is a plain old sub');
+ isa_ok($reader, 'Class::MOP::Method');
+ isa_ok($writer, 'Class::MOP::Method');
}
my $attr_clone = $attr->clone();
use Scalar::Util 'blessed', 'reftype';
-use Test::More tests => 35;
+use Test::More tests => 37;
BEGIN {
use_ok('Class::MOP');
my $writer = $gorch_attr->get_write_method_ref;
isa_ok($reader, 'Class::MOP::Method');
- ok(!blessed($writer), '... it is not a plain old sub');
+ ok(blessed($writer), '... it is not a plain old sub');
+ isa_ok($writer, 'Class::MOP::Method');
is($reader->fully_qualified_name, 'Foo::get_gorch', '... it is the sub we are looking for');
+ is($writer->fully_qualified_name, 'Foo::__ANON__', '... it is the sub we are looking for');
}