Beginning of dzilization
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / Array / sort.pm
1 package Moose::Meta::Method::Accessor::Native::Array::sort;
2
3 use strict;
4 use warnings;
5
6 use Params::Util ();
7
8 our $AUTHORITY = 'cpan:STEVAN';
9
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 };
20
21 sub _maximum_arguments { 1 }
22
23 sub _inline_check_arguments {
24     my $self = shift;
25
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     );
33 }
34
35 sub _return_value {
36     my $self = shift;
37     my ($slot_access) = @_;
38
39     return '$_[0] '
40              . '? sort { $_[0]->($a, $b) } @{ (' . $slot_access . ') } '
41              . ': sort @{ (' . $slot_access . ') }';
42 }
43
44 no Moose::Role;
45
46 1;