Commit | Line | Data |
---|---|---|
910684ee | 1 | package Moose::Meta::Method::Accessor::Native::Array::sort; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
88e88a7b | 6 | use Params::Util (); |
7 | ||
8b9641b8 | 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 | }; | |
910684ee | 18 | |
a7821be5 | 19 | sub _maximum_arguments { 1 } |
910684ee | 20 | |
21 | sub _inline_check_arguments { | |
e3181911 | 22 | my $self = shift; |
23 | ||
53a4677c | 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 | ); | |
910684ee | 31 | } |
32 | ||
33 | sub _return_value { | |
53a4677c | 34 | my $self = shift; |
35 | my ($slot_access) = @_; | |
910684ee | 36 | |
53a4677c | 37 | return '$_[0] ' |
38 | . '? sort { $_[0]->($a, $b) } @{ (' . $slot_access . ') } ' | |
39 | . ': sort @{ (' . $slot_access . ') }'; | |
910684ee | 40 | } |
41 | ||
8b9641b8 | 42 | no Moose::Role; |
43 | ||
910684ee | 44 | 1; |