Also conflict on Fey::ORM
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / Array / natatime.pm
1 package Moose::Meta::Method::Accessor::Native::Array::natatime;
2
3 use strict;
4 use warnings;
5
6 use List::MoreUtils;
7
8 our $VERSION = '1.14';
9 $VERSION = eval $VERSION;
10 our $AUTHORITY = 'cpan:STEVAN';
11
12 use Moose::Role;
13
14 with 'Moose::Meta::Method::Accessor::Native::Reader' => {
15     -excludes => [
16         qw(
17             _minimum_arguments
18             _maximum_arguments
19             _inline_check_arguments
20             _inline_return_value
21             )
22     ]
23 };
24
25 sub _minimum_arguments {1}
26
27 sub _maximum_arguments {2}
28
29 sub _inline_check_arguments {
30     my $self = shift;
31
32     return $self->_inline_throw_error(
33         q{'The n value passed to natatime must be an integer'})
34         . ' unless defined $_[0] && $_[0] =~ /^\\d+$/;' . "\n"
35         . $self->_inline_throw_error(
36         q{'The second argument passed to natatime must be a code reference'})
37         . q{ if defined $_[1] && ( ref $_[1] || q{} ) ne 'CODE';};
38 }
39
40 sub _inline_return_value {
41     my ( $self, $slot_access ) = @_;
42
43     return
44         "my \$iter = List::MoreUtils::natatime( \$_[0], \@{ $slot_access } );"
45         . "\n"
46         . 'if ( $_[1] ) {' . "\n"
47         . 'while (my @vals = $iter->()) {' . "\n"
48         . '$_[1]->(@vals);' . "\n" . '}' . "\n"
49         . '} else {' . "\n"
50         . 'return $iter;' . "\n" . '}';
51 }
52
53 # Not called, but needed to satisfy the Reader role
54 sub _return_value { }
55
56 no Moose::Role;
57
58 1;