Refactored native trait accessors so they are done entirely in roles.
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / Array / sort.pm
CommitLineData
910684ee 1package Moose::Meta::Method::Accessor::Native::Array::sort;
2
3use strict;
4use warnings;
5
10bd99ec 6our $VERSION = '1.14';
910684ee 7$VERSION = eval $VERSION;
8our $AUTHORITY = 'cpan:STEVAN';
9
8b9641b8 10use Moose::Role;
11
12with 'Moose::Meta::Method::Accessor::Native::Reader' => {
13 -excludes => [
14 qw(
15 _maximum_arguments
16 _inline_check_arguments
17 )
18 ]
19};
910684ee 20
a7821be5 21sub _maximum_arguments { 1 }
910684ee 22
23sub _inline_check_arguments {
e3181911 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';};
910684ee 29}
30
31sub _return_value {
32 my $self = shift;
33 my $slot_access = shift;
34
35 return
a7821be5 36 "\$_[0] ? sort { \$_[0]->( \$a, \$b ) } \@{ ${slot_access} } : sort \@{ $slot_access }";
910684ee 37}
38
8b9641b8 39no Moose::Role;
40
910684ee 411;