Commit | Line | Data |
---|---|---|
f7fd22b6 | 1 | package Moose::Meta::Method::Accessor::Native::Array::first; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
f5f08b5f | 6 | use List::Util (); |
88e88a7b | 7 | use Params::Util (); |
f5f08b5f | 8 | |
8b9641b8 | 9 | use Moose::Role; |
10 | ||
11 | with 'Moose::Meta::Method::Accessor::Native::Reader' => { | |
12 | -excludes => [ | |
13 | qw( | |
14 | _minimum_arguments | |
15 | _maximum_arguments | |
16 | _inline_check_arguments | |
17 | ) | |
18 | ] | |
19 | }; | |
f7fd22b6 | 20 | |
a7821be5 | 21 | sub _minimum_arguments { 1 } |
22 | ||
23 | sub _maximum_arguments { 1 } | |
f5f08b5f | 24 | |
910684ee | 25 | sub _inline_check_arguments { |
e3181911 | 26 | my $self = shift; |
27 | ||
53a4677c | 28 | return ( |
29 | 'if (!Params::Util::_CODELIKE($_[0])) {', | |
30 | $self->_inline_throw_error( | |
31 | '"The argument passed to first must be a code reference"', | |
32 | ) . ';', | |
33 | '}', | |
34 | ); | |
910684ee | 35 | } |
36 | ||
f7fd22b6 | 37 | sub _return_value { |
53a4677c | 38 | my $self = shift; |
39 | my ($slot_access) = @_; | |
f7fd22b6 | 40 | |
1e2c801e | 41 | return '&List::Util::first($_[0], @{ (' . $slot_access . ') })'; |
f7fd22b6 | 42 | } |
43 | ||
8b9641b8 | 44 | no Moose::Role; |
45 | ||
f7fd22b6 | 46 | 1; |