4d14492ec15ed1fad5d06f7cfa1267f8e51318e6
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / Array / sort_in_place.pm
1 package Moose::Meta::Method::Accessor::Native::Array::sort_in_place;
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::Array::Writer' => {
11     -excludes => [
12         qw(
13             _maximum_arguments
14             _inline_check_arguments
15             _return_value
16             )
17     ]
18 };
19
20 sub _maximum_arguments { 1 }
21
22 sub _inline_check_arguments {
23     my $self = shift;
24
25     return (
26         'if (@_ && !Params::Util::_CODELIKE($_[0])) {',
27             $self->_inline_throw_error(
28                 '"The argument passed to sort_in_place must be a code '
29               . 'reference"',
30             ) . ';',
31         '}',
32     );
33 }
34
35 sub _adds_members { 0 }
36
37 sub _potential_value {
38     my $self = shift;
39     my ($slot_access) = @_;
40
41     return '[ $_[0] '
42              . '? sort { $_[0]->($a, $b) } @{ (' . $slot_access . ') } '
43              . ': sort @{ (' . $slot_access . ') } ]';
44 }
45
46 sub _return_value { '' }
47
48 no Moose::Role;
49
50 1;