From: Dave Rolsky Date: Tue, 22 Feb 2011 23:37:26 +0000 (-0600) Subject: First pass at Moose 2.0 compatibility X-Git-Tag: v0.24~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=28c238080ac8d1824ffb29fd20eca5550a49b182;p=gitmo%2FMooseX-ClassAttribute.git First pass at Moose 2.0 compatibility --- diff --git a/lib/MooseX/ClassAttribute/Trait/Attribute.pm b/lib/MooseX/ClassAttribute/Trait/Attribute.pm index ecfbf0f..4d3f80d 100644 --- a/lib/MooseX/ClassAttribute/Trait/Attribute.pm +++ b/lib/MooseX/ClassAttribute/Trait/Attribute.pm @@ -119,47 +119,101 @@ around clear_value => sub { ->clear_class_attribute_value( $self->name() ); }; -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() ); -}; +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;