Refactored native trait accessors so they are done entirely in roles.
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / Array / first.pm
CommitLineData
f7fd22b6 1package Moose::Meta::Method::Accessor::Native::Array::first;
2
3use strict;
4use warnings;
5
f5f08b5f 6use List::Util ();
7
10bd99ec 8our $VERSION = '1.14';
f7fd22b6 9$VERSION = eval $VERSION;
10our $AUTHORITY = 'cpan:STEVAN';
11
8b9641b8 12use Moose::Role;
13
14with 'Moose::Meta::Method::Accessor::Native::Reader' => {
15 -excludes => [
16 qw(
17 _minimum_arguments
18 _maximum_arguments
19 _inline_check_arguments
20 )
21 ]
22};
f7fd22b6 23
a7821be5 24sub _minimum_arguments { 1 }
25
26sub _maximum_arguments { 1 }
f5f08b5f 27
910684ee 28sub _inline_check_arguments {
e3181911 29 my $self = shift;
30
31 return $self->_inline_throw_error(
32 q{'The argument passed to first must be a code reference'})
33 . q{if $_[0] && ( ref $_[0] || q{} ) ne 'CODE';};
910684ee 34}
35
f7fd22b6 36sub _return_value {
37 my $self = shift;
38 my $slot_access = shift;
39
a7821be5 40 return "&List::Util::first( \$_[0], \@{ ${slot_access} } )";
f7fd22b6 41}
42
8b9641b8 43no Moose::Role;
44
f7fd22b6 451;