X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FMethod%2FAccessor%2FNative.pm;h=f5870c4fea2c2bad1d75b4f17c709b16eafb9955;hb=55c22540a16ae9b8989e385af93e838570206d95;hp=62cde0fdc17ab55e23ad001c18934bec5a6f63c8;hpb=54e259f6b6600d1ab46019c49d0117e520aa2330;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Method/Accessor/Native.pm b/lib/Moose/Meta/Method/Accessor/Native.pm index 62cde0f..f5870c4 100644 --- a/lib/Moose/Meta/Method/Accessor/Native.pm +++ b/lib/Moose/Meta/Method/Accessor/Native.pm @@ -6,30 +6,17 @@ use warnings; use Carp qw( confess ); use Scalar::Util qw( blessed weaken ); -our $VERSION = '1.14'; +our $VERSION = '1.15'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Method::Accessor', 'Moose::Meta::Method::Delegation'; +use Moose::Role; -sub new { +around new => sub { + my $orig = shift; my $class = shift; my %options = @_; - die "Cannot instantiate a $class object directly" - if $class eq __PACKAGE__; - - ( exists $options{attribute} ) - || confess "You must supply an attribute to construct with"; - - ( blessed( $options{attribute} ) - && $options{attribute}->isa('Class::MOP::Attribute') ) - || confess - "You must supply an attribute which is a 'Class::MOP::Attribute' instance"; - - ( $options{package_name} && $options{name} ) - || confess "You must supply the package_name and name parameters"; - exists $options{curried_arguments} || ( $options{curried_arguments} = [] ); @@ -38,25 +25,20 @@ sub new { || confess 'You must supply a curried_arguments which is an ARRAY reference'; - $options{delegate_to_method} = lc( ( split /::/, $class)[-1] ); - $options{definition_context} = $options{attribute}->definition_context; - my $self = $class->_new( \%options ); + $options{accessor_type} = 'native'; - weaken( $self->{'attribute'} ); + return $class->$orig(%options); +}; - $self->_initialize_body; - - return $self; -} - -sub _new { +around _new => sub { + shift; my $class = shift; my $options = @_ == 1 ? $_[0] : {@_}; return bless $options, $class; -} +}; sub root_types { (shift)->{'root_types'} } @@ -115,28 +97,26 @@ sub _inline_check_argument_count { sub _minimum_arguments { 0 } sub _maximum_arguments { undef } -sub _inline_check_arguments { q{} } - -sub _inline_get { +override _inline_get => sub { my ( $self, $instance ) = @_; return $self->_slot_access_can_be_inlined - ? $self->SUPER::_inline_get($instance) + ? super() : "${instance}->\$reader"; -} +}; -sub _inline_store { +override _inline_store => sub { my ( $self, $instance, $value ) = @_; return $self->_slot_access_can_be_inlined - ? $self->SUPER::_inline_store( $instance, $value ) + ? super() : "${instance}->\$writer($value)"; -} +}; -sub _eval_environment { +override _eval_environment => sub { my $self = shift; - my $env = $self->SUPER::_eval_environment(@_); + my $env = super(); $env->{'@curried'} = $self->curried_arguments; @@ -153,7 +133,7 @@ sub _eval_environment { $env->{'$writer'} = \$writer; return $env; -} +}; sub _slot_access_can_be_inlined { my $self = shift; @@ -161,4 +141,6 @@ sub _slot_access_can_be_inlined { return $self->is_inline && $self->_instance_is_inlinable; } +no Moose::Role; + 1;