From: Dave Rolsky Date: Sat, 18 Sep 2010 16:18:38 +0000 (-0500) Subject: Move some code from Array to Native since it will be shared by many native accessors X-Git-Tag: 1.15~136 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=855f4af8da6dac949382503df5f932448f6a8036;p=gitmo%2FMoose.git Move some code from Array to Native since it will be shared by many native accessors --- diff --git a/lib/Moose/Meta/Method/Accessor/Native.pm b/lib/Moose/Meta/Method/Accessor/Native.pm index 17f6a46..de7ec8b 100644 --- a/lib/Moose/Meta/Method/Accessor/Native.pm +++ b/lib/Moose/Meta/Method/Accessor/Native.pm @@ -76,4 +76,53 @@ sub _eval_environment { return $env; } +sub _inline_curried_arguments { + my $self = shift; + + return q{} unless @{ $self->curried_arguments }; + + return 'unshift @_, @curried;' +} + +sub _inline_check_argument_count { + my $self = shift; + + my $code = q{}; + + if ( my $min = $self->_minimum_arguments ) { + my $err_msg = sprintf( + q{"Cannot call %s without at least %s argument%s"}, + $self->delegate_to_method, + $min, + ( $min == 1 ? q{} : 's' ) + ); + + $code + .= "\n" + . $self->_inline_throw_error($err_msg) + . " unless \@_ >= $min;"; + } + + if ( defined( my $max = $self->_maximum_arguments ) ) { + my $err_msg = sprintf( + q{"Cannot call %s with %s argument%s"}, + $self->delegate_to_method, + ( $max ? "more than $max" : 'any' ), + ( $max == 1 ? q{} : 's' ) + ); + + $code + .= "\n" + . $self->_inline_throw_error($err_msg) + . " if \@_ > $max;"; + } + + return $code; +} + +sub _minimum_arguments { 0 } +sub _maximum_arguments { undef } + +sub _inline_check_arguments { q{} } + 1; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array.pm b/lib/Moose/Meta/Method/Accessor/Native/Array.pm index 073a264..88c4a4f 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array.pm @@ -3,7 +3,6 @@ package Moose::Meta::Method::Accessor::Native::Array; use strict; use warnings; -use B; use Scalar::Util qw( looks_like_number ); our $VERSION = '1.13'; @@ -12,55 +11,6 @@ our $AUTHORITY = 'cpan:STEVAN'; use base 'Moose::Meta::Method::Accessor::Native'; -sub _inline_curried_arguments { - my $self = shift; - - return q{} unless @{ $self->curried_arguments }; - - return 'unshift @_, @curried;' -} - -sub _inline_check_argument_count { - my $self = shift; - - my $code = q{}; - - if ( my $min = $self->_minimum_arguments ) { - my $err_msg = sprintf( - q{"Cannot call %s without at least %s argument%s"}, - $self->delegate_to_method, - $min, - ( $min == 1 ? q{} : 's' ) - ); - - $code - .= "\n" - . $self->_inline_throw_error($err_msg) - . " unless \@_ >= $min;"; - } - - if ( defined( my $max = $self->_maximum_arguments ) ) { - my $err_msg = sprintf( - q{"Cannot call %s with %s argument%s"}, - $self->delegate_to_method, - ( $max ? "more than $max" : 'any' ), - ( $max == 1 ? q{} : 's' ) - ); - - $code - .= "\n" - . $self->_inline_throw_error($err_msg) - . " if \@_ > $max;"; - } - - return $code; -} - -sub _minimum_arguments { 0 } -sub _maximum_arguments { undef } - -sub _inline_check_arguments { q{} } - sub _inline_check_var_is_valid_index { my ( $self, $var ) = @_;