* MOP.xs
- Don't use Perl_mro_meta_init. It's not part of the public perl api.
(Florian Ragwitz)
- * Class::MOP::Attribute
- - Allow default values to be objects with overloaded codification.
- (Florian Ragwitz)
- - Test the above. (Rhesa Rozendaal)
* t/082_get_code_info.t
- Add $^P &= ~0x200; (per Ovid's suggestion) in order to not munger
anonymous subs when under -d and so making the tests succeed
}
sub is_default_a_coderef {
- my ($value) = $_[0]->{'default'};
- return unless ref($value);
- return ref($value) eq 'CODE' || (blessed($value) && $value->can('(&{}'));
+ ('CODE' eq ref($_[0]->{'default'}))
}
sub default {
use Scalar::Util 'reftype', 'blessed';
-use Test::More tests => 104;
+use Test::More tests => 100;
use Test::Exception;
use Class::MOP;
is($attr->builder, 'foo_builder', '... $attr->builder == foo_builder');
}
-
-{
- for my $value ({}, bless({}, 'Foo')) {
- throws_ok {
- Class::MOP::Attribute->new('$foo', default => $value);
- } qr/References are not allowed as default values/;
- }
-}
-
-{
- {
- package Method;
- use overload '&{}' => sub { sub { $_[0] } };
- }
-
- my $attr;
- lives_ok {
- $attr = Class::MOP::Attribute->new('$foo', default => bless({}, 'Method'));
- } 'objects with overloaded codification accepted as default';
-
- is($attr->default(42), 42, 'default calculated correctly with overloaded object');
-}