Refactored native trait accessors so they are done entirely in roles.
[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 our $VERSION = '1.14';
7 $VERSION = eval $VERSION;
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 $self->_inline_throw_error(
27         q{'The argument passed to sort must be a code reference'})
28         . q{if $_[0] && ( ref $_[0] || q{} ) ne 'CODE';};
29 }
30
31 sub _return_value {
32     my $self        = shift;
33     my $slot_access = shift;
34
35     return
36         "\$_[0] ? sort { \$_[0]->( \$a, \$b ) } \@{ ${slot_access} } : sort \@{ $slot_access }";
37 }
38
39 no Moose::Role;
40
41 1;