From: Stevan Little Date: Thu, 31 Aug 2006 21:33:24 +0000 (+0000) Subject: whoops-bug X-Git-Tag: 0_35~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=dc76a41004a91c77e15587965e84899327e3dfb8;p=gitmo%2FClass-MOP.git whoops-bug --- diff --git a/lib/Class/MOP/Class/Immutable.pm b/lib/Class/MOP/Class/Immutable.pm index 802a3ba..942708c 100644 --- a/lib/Class/MOP/Class/Immutable.pm +++ b/lib/Class/MOP/Class/Immutable.pm @@ -12,6 +12,19 @@ our $AUTHORITY = 'cpan:STEVAN'; use base 'Class::MOP::Class'; +# enforce the meta-circularity here +# and hide the Immutable part + +sub meta { + my $self = shift; + # if it is not blessed, then someone is asking + # for the meta of Class::MOP::Class::Immutable + return Class::MOP::Class->initialize($self) unless blessed($self); + # otherwise, they are asking for the metaclass + # which has been made immutable, which is itself + return $self; +} + # methods which can *not* be called for my $meth (qw( add_method diff --git a/t/000_load.t b/t/000_load.t index b9edef2..40d59ff 100644 --- a/t/000_load.t +++ b/t/000_load.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 19; +use Test::More tests => 22; BEGIN { use_ok('Class::MOP'); @@ -79,5 +79,17 @@ is_deeply( "Class::MOP::Package-" . $Class::MOP::Package::VERSION . "-cpan:STEVAN", ], '... got all the metaclass identifiers'); - - + +# testing the meta-circularity of the system + +is(Class::MOP::Class->meta, Class::MOP::Class->meta->meta, + '... Class::MOP::Class->meta == Class::MOP::Class->meta->meta'); + +is(Class::MOP::Class->meta, Class::MOP::Class->meta->meta->meta, + '... Class::MOP::Class->meta == Class::MOP::Class->meta->meta->meta'); + +is(Class::MOP::Class->meta, Class::MOP::Class->meta->meta->meta->meta, + '... Class::MOP::Class->meta == Class::MOP::Class->meta->meta->meta->meta'); + + +