ad5365a780a3661bbcaf80c23090c7c4db6feac9
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / Array / first.pm
1 package Moose::Meta::Method::Accessor::Native::Array::first;
2
3 use strict;
4 use warnings;
5
6 use List::Util ();
7 use Params::Util ();
8
9 our $AUTHORITY = 'cpan:STEVAN';
10
11 use Moose::Role;
12
13 with 'Moose::Meta::Method::Accessor::Native::Reader' => {
14     -excludes => [
15         qw(
16             _minimum_arguments
17             _maximum_arguments
18             _inline_check_arguments
19             )
20     ]
21 };
22
23 sub _minimum_arguments { 1 }
24
25 sub _maximum_arguments { 1 }
26
27 sub _inline_check_arguments {
28     my $self = shift;
29
30     return (
31         'if (!Params::Util::_CODELIKE($_[0])) {',
32             $self->_inline_throw_error(
33                 '"The argument passed to first must be a code reference"',
34             ) . ';',
35         '}',
36     );
37 }
38
39 sub _return_value {
40     my $self = shift;
41     my ($slot_access) = @_;
42
43     return '&List::Util::first($_[0], @{ (' . $slot_access . ') })';
44 }
45
46 no Moose::Role;
47
48 1;