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