make github the primary repository
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / Array / sort.pm
CommitLineData
910684ee 1package Moose::Meta::Method::Accessor::Native::Array::sort;
2
3use strict;
4use warnings;
5
88e88a7b 6use Params::Util ();
7
8b9641b8 8use Moose::Role;
9
00bbc132 10with 'Moose::Meta::Method::Accessor::Native::Reader';
910684ee 11
a7821be5 12sub _maximum_arguments { 1 }
910684ee 13
14sub _inline_check_arguments {
e3181911 15 my $self = shift;
16
53a4677c 17 return (
18 'if (@_ && !Params::Util::_CODELIKE($_[0])) {',
19 $self->_inline_throw_error(
20 '"The argument passed to sort must be a code reference"',
21 ) . ';',
22 '}',
23 );
910684ee 24}
25
26sub _return_value {
53a4677c 27 my $self = shift;
28 my ($slot_access) = @_;
910684ee 29
53a4677c 30 return '$_[0] '
31 . '? sort { $_[0]->($a, $b) } @{ (' . $slot_access . ') } '
32 . ': sort @{ (' . $slot_access . ') }';
910684ee 33}
34
8b9641b8 35no Moose::Role;
36
910684ee 371;