X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FMethod%2FAccessor%2FNative%2FArray%2Fsort.pm;h=02feb9e4309ccddb37dffdedd993b43bdbb0e2d8;hb=d5f6cadef8d83deaf7dd95302908cd4f61aeab8a;hp=4b633dc9923c7e340ee7e650c4539f6b0bed17bf;hpb=e3181911a75bfb896df9ec013142348b1646acdf;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/sort.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/sort.pm index 4b633dc..02feb9e 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/sort.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/sort.pm @@ -3,28 +3,42 @@ package Moose::Meta::Method::Accessor::Native::Array::sort; use strict; use warnings; -our $VERSION = '1.13'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; +use Params::Util (); -use base 'Moose::Meta::Method::Accessor::Native::Array::Reader'; +use Moose::Role; + +with 'Moose::Meta::Method::Accessor::Native::Reader' => { + -excludes => [ + qw( + _maximum_arguments + _inline_check_arguments + ) + ] +}; sub _maximum_arguments { 1 } sub _inline_check_arguments { my $self = shift; - return $self->_inline_throw_error( - q{'The argument passed to sort must be a code reference'}) - . q{if $_[0] && ( ref $_[0] || q{} ) ne 'CODE';}; + return ( + 'if (@_ && !Params::Util::_CODELIKE($_[0])) {', + $self->_inline_throw_error( + '"The argument passed to sort must be a code reference"', + ) . ';', + '}', + ); } sub _return_value { - my $self = shift; - my $slot_access = shift; + my $self = shift; + my ($slot_access) = @_; - return - "\$_[0] ? sort { \$_[0]->( \$a, \$b ) } \@{ ${slot_access} } : sort \@{ $slot_access }"; + return '$_[0] ' + . '? sort { $_[0]->($a, $b) } @{ (' . $slot_access . ') } ' + . ': sort @{ (' . $slot_access . ') }'; } +no Moose::Role; + 1;