Adopt Catalyst::ClassData to latest Class::MOP::Class changes.
[catagits/Catalyst-Runtime.git] / lib / Catalyst / ClassData.pm
index 87b68c9..553a851 100644 (file)
@@ -3,7 +3,6 @@ package Catalyst::ClassData;
 use Moose::Role;
 use Class::MOP;
 use Class::MOP::Object;
-use Scalar::Util 'blessed';
 
 sub mk_classdata {
   my ($class, $attribute) = @_;
@@ -13,21 +12,10 @@ sub mk_classdata {
   my $slot = '$'.$attribute;
   my $accessor =  sub {
     my $pkg = ref $_[0] || $_[0];
+    # Hack - delberately create a metaclass instance
     my $meta = $pkg->Class::MOP::Object::meta();
     if (@_ > 1) {
       $meta->namespace->{$attribute} = \$_[1];
-      no strict 'refs';
-      if (! *{"${pkg}::${attribute}"}{CODE} ) {
-        foreach my $super ( $meta->linearized_isa ) {
-          # If there is a code symbol for this class data in a parent class, but not in our 
-          # class then copy it into our package. This is evil.
-          my $parent_symbol = *{"${super}::${attribute}"}{CODE} ? \&{"${super}::${attribute}"} : undef;
-          if (defined $parent_symbol) {
-            *{"${pkg}::${attribute}"} = $parent_symbol;
-            last;
-          }
-        }      
-      }
       return $_[1];
     }
 
@@ -56,17 +44,18 @@ sub mk_classdata {
     unless ref $accessor eq 'CODE';
 
   my $meta = $class->Class::MOP::Object::meta();
-  my $immutable_options;
-  if( $meta->is_immutable ){
-    $immutable_options = $meta->get_immutable_options;
-    $meta->make_mutable;
-  }
+  confess "${class}'s metaclass is not a Class::MOP::Class"
+    unless $meta->isa('Class::MOP::Class');
+
+  my $was_immutable = $meta->is_immutable;
+  $meta->make_mutable if $was_immutable;
+
   my $alias = "_${attribute}_accessor";
   $meta->add_method($alias, $accessor);
   $meta->add_method($attribute, $accessor);
-  if(defined $immutable_options){
-    $meta->make_immutable(%{ $immutable_options });
-  }
+
+  $meta->make_immutable if $was_immutable;
+
   $class->$attribute($_[2]) if(@_ > 2);
   return $accessor;
 }
@@ -78,7 +67,7 @@ __END__
 
 =head1 NAME
 
-Catalyst::ClassData - Class data acessors
+Catalyst::ClassData - Class data accessors
 
 =head1 METHODS