From: Stevan Little Date: Wed, 19 Apr 2006 20:05:45 +0000 (+0000) Subject: anon-classes X-Git-Tag: 0_26~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c3e7c446227eef2b683e872dd6e8cecfcf5e81a6;p=gitmo%2FClass-MOP.git anon-classes --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 2f4fbba..3ddbbae 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -134,11 +134,13 @@ sub create { return $meta; } -sub create_anon_class { - my ($class, %options) = @_; - require Digest::MD5; - my $package_name = 'Class::MOP::Class::__ANON__::' . Digest::MD5::md5_hex({} . time() . $$ . rand()); - return $class->create($package_name, '0.00', %options); +{ + my $ANON_CLASS_SERIAL = 0; + sub create_anon_class { + my ($class, %options) = @_; + my $package_name = 'Class::MOP::Class::__ANON__::SERIAL::' . ++$ANON_CLASS_SERIAL; + return $class->create($package_name, '0.00', %options); + } } ## Attribute readers diff --git a/t/018_anon_class.t b/t/018_anon_class.t index 57e900a..6534662 100644 --- a/t/018_anon_class.t +++ b/t/018_anon_class.t @@ -13,7 +13,7 @@ BEGIN { my $anon_class = Class::MOP::Class->create_anon_class(); isa_ok($anon_class, 'Class::MOP::Class'); -like($anon_class->name, qr/Class::MOP::Class::__ANON__::[0-9a-f]/, '... got an anon class package name'); +like($anon_class->name, qr/Class::MOP::Class::__ANON__::SERIAL::[0-9]+/, '... got an anon class package name'); lives_ok { $anon_class->add_method('foo' => sub { "__ANON__::foo" });