From: Stevan Little Date: Mon, 8 May 2006 20:03:15 +0000 (+0000) Subject: foo X-Git-Tag: 0_29_02~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8a402c9e291e36f005e01c1294639df0d72adb41;p=gitmo%2FClass-MOP.git foo --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index ccf3521..111e20f 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -127,7 +127,7 @@ sub meta { Class::MOP::Class->initialize(blessed($_[0]) || $_[0]) } my $self = shift; return unless $self->name =~ /^$ANON_CLASS_PREFIX/; my ($serial_id) = ($self->name =~ /^$ANON_CLASS_PREFIX(\d+)/); - no strict 'refs'; + no strict 'refs'; foreach my $key (keys %{$ANON_CLASS_PREFIX . $serial_id}) { delete ${$ANON_CLASS_PREFIX . $serial_id}{$key}; } diff --git a/t/018_anon_class.t b/t/018_anon_class.t index d8d43fe..1eb3aa6 100644 --- a/t/018_anon_class.t +++ b/t/018_anon_class.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 16; +use Test::More tests => 24; use Test::Exception; BEGIN { @@ -20,6 +20,7 @@ BEGIN { } my $anon_class_id; +my $instance; { my $anon_class = Class::MOP::Class->create_anon_class(); isa_ok($anon_class, 'Class::MOP::Class'); @@ -45,9 +46,9 @@ my $anon_class_id; lives_ok { $anon_class->add_method('foo' => sub { "__ANON__::foo" }); } '... added a method to my anon-class'; - ok($anon_class->has_method('foo'), '... we have a foo method now'); + ok($anon_class->has_method('foo'), '... we have a foo method now'); - my $instance = $anon_class->new_object(); + $instance = $anon_class->new_object(); isa_ok($instance, $anon_class->name); isa_ok($instance, 'Foo'); @@ -57,6 +58,25 @@ my $anon_class_id; ok(!exists $main::Class::MOP::Class::__ANON__::SERIAL::{$anon_class_id . '::'}, '... the package no longer exists'); +# the superclass relationship actually +# still exists for the instance ... +isa_ok($instance, 'Foo'); + +# and oddly enough we can still +# call methods on our instance +can_ok($instance, 'foo'); +can_ok($instance, 'bar'); + +is($instance->foo, '__ANON__::foo', '... got the right return value of our foo method'); +is($instance->bar, 'Foo::bar', '... got the right return value of our bar method'); + +# but it breaks down when we try to create another one ... + +my $instance_2 = bless {} => ref($instance); +isa_ok($instance_2, ref($instance)); +ok(!$instance_2->isa('Foo'), '... but the new instance is not a Foo'); +ok(!$instance_2->can('foo'), '... and it can no longer call the foo method'); + # NOTE: # I bumped this test up to 100_000 instances, and # still got not conflicts. If your application needs