02feb9e4309ccddb37dffdedd993b43bdbb0e2d8
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / Array / sort.pm
1 package Moose::Meta::Method::Accessor::Native::Array::sort;
2
3 use strict;
4 use warnings;
5
6 use Params::Util ();
7
8 use Moose::Role;
9
10 with 'Moose::Meta::Method::Accessor::Native::Reader' => {
11     -excludes => [
12         qw(
13             _maximum_arguments
14             _inline_check_arguments
15             )
16     ]
17 };
18
19 sub _maximum_arguments { 1 }
20
21 sub _inline_check_arguments {
22     my $self = shift;
23
24     return (
25         'if (@_ && !Params::Util::_CODELIKE($_[0])) {',
26             $self->_inline_throw_error(
27                 '"The argument passed to sort must be a code reference"',
28             ) . ';',
29         '}',
30     );
31 }
32
33 sub _return_value {
34     my $self = shift;
35     my ($slot_access) = @_;
36
37     return '$_[0] '
38              . '? sort { $_[0]->($a, $b) } @{ (' . $slot_access . ') } '
39              . ': sort @{ (' . $slot_access . ') }';
40 }
41
42 no Moose::Role;
43
44 1;