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