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 | ||
910684ee | 8 | our $AUTHORITY = 'cpan:STEVAN'; |
9 | ||
8b9641b8 | 10 | use Moose::Role; |
11 | ||
12 | with 'Moose::Meta::Method::Accessor::Native::Reader' => { | |
13 | -excludes => [ | |
14 | qw( | |
15 | _maximum_arguments | |
16 | _inline_check_arguments | |
17 | ) | |
18 | ] | |
19 | }; | |
910684ee | 20 | |
a7821be5 | 21 | sub _maximum_arguments { 1 } |
910684ee | 22 | |
23 | sub _inline_check_arguments { | |
e3181911 | 24 | my $self = shift; |
25 | ||
53a4677c | 26 | return ( |
27 | 'if (@_ && !Params::Util::_CODELIKE($_[0])) {', | |
28 | $self->_inline_throw_error( | |
29 | '"The argument passed to sort must be a code reference"', | |
30 | ) . ';', | |
31 | '}', | |
32 | ); | |
910684ee | 33 | } |
34 | ||
35 | sub _return_value { | |
53a4677c | 36 | my $self = shift; |
37 | my ($slot_access) = @_; | |
910684ee | 38 | |
53a4677c | 39 | return '$_[0] ' |
40 | . '? sort { $_[0]->($a, $b) } @{ (' . $slot_access . ') } ' | |
41 | . ': sort @{ (' . $slot_access . ') }'; | |
910684ee | 42 | } |
43 | ||
8b9641b8 | 44 | no Moose::Role; |
45 | ||
910684ee | 46 | 1; |