From: Florian Ragwitz Date: Sun, 14 Dec 2008 20:10:47 +0000 (+0000) Subject: Revert "Allow attribute defaults to be objects with overloaded codification." X-Git-Tag: 0.73~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4e55a580c5637a075a55c87e412eaafaeef35283;p=gitmo%2FClass-MOP.git Revert "Allow attribute defaults to be objects with overloaded codification." This reverts commit 7070. 17:09:35 < stevan> overloaded stuff is not the same as regular stuff 17:09:59 < stevan> Perl's overloading sucks ass basically 17:10:39 < stevan> and I dont think we should have support for it in the core 17:10:52 < stevan> it is too fragile and unreliable 17:11:16 < stevan> I dont want to get into the edge case hell that it creates 20:14:59 < stevan> rafl: additionally, I dont think that this is a correct use case in the test 20:15:07 < stevan> default take a sub ref, not a method 20:15:14 < stevan> for methods, you use build 20:15:22 < stevan> anything else is incorrect usage --- diff --git a/Changes b/Changes index 48f260a..0b654a5 100644 --- a/Changes +++ b/Changes @@ -3,10 +3,6 @@ Revision history for Perl extension Class-MOP. * 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 diff --git a/lib/Class/MOP/Attribute.pm b/lib/Class/MOP/Attribute.pm index 82d7bc7..97b7d78 100644 --- a/lib/Class/MOP/Attribute.pm +++ b/lib/Class/MOP/Attribute.pm @@ -241,9 +241,7 @@ sub get_write_method_ref { } 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 { diff --git a/t/020_attribute.t b/t/020_attribute.t index 30bb9cd..4dfbc2e 100644 --- a/t/020_attribute.t +++ b/t/020_attribute.t @@ -5,7 +5,7 @@ use warnings; use Scalar::Util 'reftype', 'blessed'; -use Test::More tests => 104; +use Test::More tests => 100; use Test::Exception; use Class::MOP; @@ -227,25 +227,3 @@ dies_ok { Class::MOP::Attribute->name } q{... can't call name() as a class metho 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'); -}