From: Dave Rolsky Date: Wed, 16 Dec 2009 16:44:28 +0000 (-0600) Subject: Forgot to commit -a last time - rest of MiniTrait implementation X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=182e3730be5895420626de1141bded99649bd572;p=gitmo%2FClass-MOP.git Forgot to commit -a last time - rest of MiniTrait implementation --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 8678844..b9f9c21 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -980,16 +980,7 @@ sub _immutable_metaclass { ); Class::MOP::load_class($trait); - for my $meth ( Class::MOP::Class->initialize($trait)->get_all_methods ) { - my $meth_name = $meth->name; - - if ( $immutable_meta->find_method_by_name( $meth_name ) ) { - $immutable_meta->add_around_method_modifier( $meth_name, $meth->body ); - } - else { - $immutable_meta->add_method( $meth_name, $meth->clone ); - } - } + $trait->apply($immutable_meta); $immutable_meta->make_immutable( inline_constructor => 0, diff --git a/lib/Class/MOP/Class/Immutable/Trait.pm b/lib/Class/MOP/Class/Immutable/Trait.pm index 53c4420..b142a35 100644 --- a/lib/Class/MOP/Class/Immutable/Trait.pm +++ b/lib/Class/MOP/Class/Immutable/Trait.pm @@ -12,6 +12,8 @@ our $VERSION = '0.95'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; +use base 'Class::MOP::MiniTrait'; + # the original class of the metaclass instance sub _get_mutable_metaclass_name { $_[0]{__immutable}{original_class} } diff --git a/t/000_load.t b/t/000_load.t index 3aa0fcd..222d73a 100644 --- a/t/000_load.t +++ b/t/000_load.t @@ -16,6 +16,7 @@ BEGIN { use_ok('Class::MOP::Method::Generated'); use_ok('Class::MOP::Method::Accessor'); use_ok('Class::MOP::Method::Constructor'); + use_ok('Class::MOP::MiniTrait'); use_ok('Class::MOP::Instance'); use_ok('Class::MOP::Object'); } @@ -36,6 +37,7 @@ my %METAS = ( 'Class::MOP::Method::Wrapped' => Class::MOP::Method::Wrapped->meta, 'Class::MOP::Instance' => Class::MOP::Instance->meta, 'Class::MOP::Object' => Class::MOP::Object->meta, + 'Class::MOP::MiniTrait' => Class::MOP::MiniTrait->meta, 'Class::MOP::Class::Immutable::Trait' => Class::MOP::class_of('Class::MOP::Class::Immutable::Trait'), 'Class::MOP::Class::Immutable::Class::MOP::Class' => Class::MOP::Class::Immutable::Class::MOP::Class->meta, ); @@ -43,11 +45,13 @@ my %METAS = ( ok( Class::MOP::is_class_loaded($_), '... ' . $_ . ' is loaded' ) for keys %METAS; +my %expect_mutable = map { $_ => 1 } + qw( Class::MOP::Class::Immutable::Trait Class::MOP::MiniTrait ); for my $meta (values %METAS) { # the trait shouldn't be made immutable, it doesn't actually do anything, # and it doesn't even matter because it's not a class that will be # instantiated - if ($meta->name eq 'Class::MOP::Class::Immutable::Trait') { + if ( $expect_mutable{ $meta->name} ) { ok( $meta->is_mutable(), '... ' . $meta->name . ' is mutable' ); } else { @@ -77,6 +81,7 @@ is_deeply( Class::MOP::Method::Generated->meta, Class::MOP::Method::Inlined->meta, Class::MOP::Method::Wrapped->meta, + Class::MOP::MiniTrait->meta, Class::MOP::Module->meta, Class::MOP::Object->meta, Class::MOP::Package->meta, @@ -99,6 +104,7 @@ is_deeply( Class::MOP::Method::Generated Class::MOP::Method::Inlined Class::MOP::Method::Wrapped + Class::MOP::MiniTrait Class::MOP::Module Class::MOP::Object Class::MOP::Package