First pass at Moose 2.0 compatibility
[gitmo/MooseX-ClassAttribute.git] / lib / MooseX / ClassAttribute / Trait / Attribute.pm
index a4a2b93..4d3f80d 100644 (file)
@@ -3,8 +3,6 @@ package MooseX::ClassAttribute::Trait::Attribute;
 use strict;
 use warnings;
 
-use MooseX::ClassAttribute::Meta::Method::Accessor;
-
 use namespace::autoclean;
 use Moose::Role;
 
@@ -12,11 +10,7 @@ use Moose::Role;
 # because it overrides a lot of behavior. However, as a subclass it
 # won't cooperate with _other_ subclasses.
 
-around 'accessor_metaclass' => sub {
-    return 'MooseX::ClassAttribute::Meta::Method::Accessor';
-};
-
-around '_process_options' => sub {
+around _process_options => sub {
     my $orig    = shift;
     my $class   = shift;
     my $name    = shift;
@@ -39,7 +33,7 @@ around attach_to_class => sub {
         unless $self->is_lazy();
 };
 
-around 'detach_from_class' => sub {
+around detach_from_class => sub {
     my $orig = shift;
     my $self = shift;
     my $meta = shift;
@@ -61,7 +55,7 @@ sub _initialize {
     }
 }
 
-around 'default' => sub {
+around default => sub {
     my $orig = shift;
     my $self = shift;
 
@@ -74,7 +68,7 @@ around 'default' => sub {
     return $default;
 };
 
-around '_call_builder' => sub {
+around _call_builder => sub {
     shift;
     my $self  = shift;
     my $class = shift;
@@ -91,7 +85,7 @@ around '_call_builder' => sub {
             . "'" );
 };
 
-around 'set_value' => sub {
+around set_value => sub {
     shift;
     my $self = shift;
     shift;    # ignoring instance or class name
@@ -101,7 +95,7 @@ around 'set_value' => sub {
         ->set_class_attribute_value( $self->name() => $value );
 };
 
-around 'get_value' => sub {
+around get_value => sub {
     shift;
     my $self = shift;
 
@@ -109,7 +103,7 @@ around 'get_value' => sub {
         ->get_class_attribute_value( $self->name() );
 };
 
-around 'has_value' => sub {
+around has_value => sub {
     shift;
     my $self = shift;
 
@@ -117,7 +111,7 @@ around 'has_value' => sub {
         ->has_class_attribute_value( $self->name() );
 };
 
-around 'clear_value' => sub {
+around clear_value => sub {
     shift;
     my $self = shift;
 
@@ -125,16 +119,110 @@ around 'clear_value' => sub {
         ->clear_class_attribute_value( $self->name() );
 };
 
+if ( $Moose::VERSION < 1.99 ) {
+    around inline_get => sub {
+        shift;
+        my $self = shift;
+
+        return $self->associated_class()
+            ->inline_get_class_slot_value( $self->slots() );
+    };
+
+    around inline_set => sub {
+        shift;
+        my $self = shift;
+        shift;
+        my $value = shift;
+
+        my $meta = $self->associated_class();
+
+        my $code
+            = $meta->inline_set_class_slot_value( $self->slots(), $value )
+            . ";";
+        $code
+            .= $meta->inline_weaken_class_slot_value( $self->slots(), $value )
+            . "    if ref $value;"
+            if $self->is_weak_ref();
+
+        return $code;
+    };
+
+    around inline_has => sub {
+        shift;
+        my $self = shift;
+
+        return $self->associated_class()
+            ->inline_is_class_slot_initialized( $self->slots() );
+    };
+
+    around inline_clear => sub {
+        shift;
+        my $self = shift;
+
+        return $self->associated_class()
+            ->inline_deinitialize_class_slot( $self->slots() );
+    };
+}
+else {
+    around _inline_instance_get => sub {
+        shift;
+        my $self = shift;
+
+        return $self->associated_class()
+            ->inline_get_class_slot_value( $self->slots() );
+    };
+
+    around _inline_instance_set => sub {
+        shift;
+        my $self = shift;
+        shift;
+        my $value = shift;
+
+        return $self->associated_class()
+            ->inline_set_class_slot_value( $self->slots(), $value );
+    };
+
+    around _inline_instance_has => sub {
+        shift;
+        my $self = shift;
+
+        return $self->associated_class()
+            ->inline_is_class_slot_initialized( $self->slots() );
+    };
+
+    around _inline_instance_clear => sub {
+        shift;
+        my $self = shift;
+
+        return $self->associated_class()
+            ->inline_deinitialize_class_slot( $self->slots() );
+    };
+
+    around _inline_weaken_value => sub {
+        shift;
+        my $self = shift;
+        shift;
+        my $value = shift;
+
+        return unless $self->is_weak_ref();
+
+        return (
+            $self->associated_class->inline_weaken_class_slot_value(
+                $self->slots(), $value
+            ),
+            'if ref ' . $value . ';',
+        );
+    };
+}
+
 1;
 
+# ABSTRACT: A trait for class attributes
+
 __END__
 
 =pod
 
-=head1 NAME
-
-MooseX::ClassAttribute::Trait::Attribute - An attribute role for classes with class attributes
-
 =head1 DESCRIPTION
 
 This role modifies the behavior of class attributes in various
@@ -145,21 +233,8 @@ metaclasses, like C<MooseX::AttributeHelpers>.
 There are no new public methods implemented by this role. All it does
 is change the behavior of a number of existing methods.
 
-=head1 AUTHOR
-
-Dave Rolsky, C<< <autarch@urth.org> >>
-
 =head1 BUGS
 
 See L<MooseX::ClassAttribute> for details.
 
-=head1 COPYRIGHT & LICENSE
-
-Copyright 2007-2008 Dave Rolsky, All Rights Reserved.
-
-This program is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
 =cut
-
-