From: Dave Rolsky Date: Mon, 28 Dec 2009 17:14:24 +0000 (-0600) Subject: Mixins no longer inherit from CMOP::Object. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9e3ca77b02a577f17dad4312b057778b30531b43;p=gitmo%2FClass-MOP.git Mixins no longer inherit from CMOP::Object. They now inherit from CMOP::Mixin, which just provides a ->meta method. --- diff --git a/lib/Class/MOP.pm b/lib/Class/MOP.pm index 01a619e..bad986d 100644 --- a/lib/Class/MOP.pm +++ b/lib/Class/MOP.pm @@ -699,6 +699,7 @@ $_->meta->make_immutable( constructor_name => undef, inline_accessors => 0, ) for qw/ + Class::MOP::Mixin Class::MOP::Mixin::AttributeCore Class::MOP::Mixin::HasAttributes Class::MOP::Mixin::HasMethods diff --git a/lib/Class/MOP/Mixin.pm b/lib/Class/MOP/Mixin.pm new file mode 100644 index 0000000..b7c20d1 --- /dev/null +++ b/lib/Class/MOP/Mixin.pm @@ -0,0 +1,13 @@ +package Class::MOP::Mixin; + +use strict; +use warnings; + +use Scalar::Util 'blessed'; + +sub meta { + require Class::MOP::Class; + Class::MOP::Class->initialize( blessed( $_[0] ) || $_[0] ); +} + +1; diff --git a/lib/Class/MOP/Mixin/AttributeCore.pm b/lib/Class/MOP/Mixin/AttributeCore.pm index f1b9089..4f47112 100644 --- a/lib/Class/MOP/Mixin/AttributeCore.pm +++ b/lib/Class/MOP/Mixin/AttributeCore.pm @@ -9,7 +9,7 @@ our $VERSION = '0.97'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Class::MOP::Object'; +use base 'Class::MOP::Mixin'; sub has_accessor { defined $_[0]->{'accessor'} } sub has_reader { defined $_[0]->{'reader'} } diff --git a/lib/Class/MOP/Mixin/HasAttributes.pm b/lib/Class/MOP/Mixin/HasAttributes.pm index 2cac5e2..d56c629 100644 --- a/lib/Class/MOP/Mixin/HasAttributes.pm +++ b/lib/Class/MOP/Mixin/HasAttributes.pm @@ -6,7 +6,7 @@ use warnings; use Carp 'confess'; use Scalar::Util 'blessed'; -use base 'Class::MOP::Object'; +use base 'Class::MOP::Mixin'; sub _attribute_map { $_[0]->{'attributes'} } sub attribute_metaclass { $_[0]->{'attribute_metaclass'} } diff --git a/lib/Class/MOP/Mixin/HasMethods.pm b/lib/Class/MOP/Mixin/HasMethods.pm index 75cb51a..82abbcc 100644 --- a/lib/Class/MOP/Mixin/HasMethods.pm +++ b/lib/Class/MOP/Mixin/HasMethods.pm @@ -7,7 +7,7 @@ use Scalar::Util 'blessed'; use Carp 'confess'; use Sub::Name 'subname'; -use base 'Class::MOP::Object'; +use base 'Class::MOP::Mixin'; sub method_metaclass { $_[0]->{'method_metaclass'} } sub wrapped_method_metaclass { $_[0]->{'wrapped_method_metaclass'} } diff --git a/lib/Class/MOP/Package.pm b/lib/Class/MOP/Package.pm index e9f388c..0fd9fdc 100644 --- a/lib/Class/MOP/Package.pm +++ b/lib/Class/MOP/Package.pm @@ -11,7 +11,7 @@ our $VERSION = '0.97'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Class::MOP::Mixin::HasMethods'; +use base 'Class::MOP::Object', 'Class::MOP::Mixin::HasMethods'; # creation ... diff --git a/t/000_load.t b/t/000_load.t index 4e0fe9d..e6abf02 100644 --- a/t/000_load.t +++ b/t/000_load.t @@ -5,6 +5,7 @@ use Test::More; BEGIN { use_ok('Class::MOP'); + use_ok('Class::MOP::Mixin'); use_ok('Class::MOP::Mixin::AttributeCore'); use_ok('Class::MOP::Mixin::HasAttributes'); use_ok('Class::MOP::Mixin::HasMethods'); @@ -32,6 +33,7 @@ my %METAS = ( 'Class::MOP::Method::Accessor' => Class::MOP::Method::Accessor->meta, 'Class::MOP::Method::Constructor' => Class::MOP::Method::Constructor->meta, + 'Class::MOP::Mixin' => Class::MOP::Mixin->meta, 'Class::MOP::Mixin::AttributeCore' => Class::MOP::Mixin::AttributeCore->meta, 'Class::MOP::Mixin::HasAttributes' => Class::MOP::Mixin::HasAttributes->meta, 'Class::MOP::Mixin::HasMethods' => Class::MOP::Mixin::HasMethods->meta, @@ -83,6 +85,7 @@ is_deeply( Class::MOP::Method::Generated->meta, Class::MOP::Method::Inlined->meta, Class::MOP::Method::Wrapped->meta, + Class::MOP::Mixin->meta, Class::MOP::Mixin::AttributeCore->meta, Class::MOP::Mixin::HasAttributes->meta, Class::MOP::Mixin::HasMethods->meta, @@ -101,6 +104,7 @@ is_deeply( Class::MOP::Class Class::MOP::Class::Immutable::Class::MOP::Class Class::MOP::Class::Immutable::Trait + Class::MOP::Mixin Class::MOP::Mixin::AttributeCore Class::MOP::Mixin::HasAttributes Class::MOP::Mixin::HasMethods diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index cb95b6b..2f0f17b 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -324,10 +324,11 @@ is_deeply( Class::MOP::Class Class::MOP::Module Class::MOP::Package - Class::MOP::Mixin::HasMethods Class::MOP::Object + Class::MOP::Mixin::HasMethods + Class::MOP::Mixin Class::MOP::Mixin::HasAttributes - Class::MOP::Object + Class::MOP::Mixin / ], '... Class::MOP::Class->class_precedence_list == [ Class::MOP::Class Class::MOP::Module Class::MOP::Package ]');