Use dzil Authority plugin - remove $AUTHORITY from code
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor / Native / Array / natatime.pm
CommitLineData
a7821be5 1package Moose::Meta::Method::Accessor::Native::Array::natatime;
2
3use strict;
4use warnings;
5
88e88a7b 6use List::MoreUtils ();
7use Params::Util ();
a7821be5 8
8b9641b8 9use Moose::Role;
10
11with 'Moose::Meta::Method::Accessor::Native::Reader' => {
12 -excludes => [
13 qw(
14 _minimum_arguments
15 _maximum_arguments
16 _inline_check_arguments
17 _inline_return_value
18 )
19 ]
20};
a7821be5 21
1e2c801e 22sub _minimum_arguments { 1 }
a7821be5 23
1e2c801e 24sub _maximum_arguments { 2 }
a7821be5 25
26sub _inline_check_arguments {
27 my $self = shift;
28
53a4677c 29 return (
30 'if (!defined($_[0]) || $_[0] !~ /^\d+$/) {',
31 $self->_inline_throw_error(
32 '"The n value passed to natatime must be an integer"',
33 ) . ';',
34 '}',
35 'if (@_ == 2 && !Params::Util::_CODELIKE($_[1])) {',
36 $self->_inline_throw_error(
37 '"The second argument passed to natatime must be a code '
38 . 'reference"',
39 ) . ';',
40 '}',
41 );
a7821be5 42}
43
44sub _inline_return_value {
53a4677c 45 my $self = shift;
46 my ($slot_access) = @_;
47
48 return (
49 'my $iter = List::MoreUtils::natatime($_[0], @{ (' . $slot_access . ') });',
50 'if ($_[1]) {',
51 'while (my @vals = $iter->()) {',
52 '$_[1]->(@vals);',
53 '}',
54 '}',
55 'else {',
56 'return $iter;',
57 '}',
58 );
a7821be5 59}
60
8b9641b8 61# Not called, but needed to satisfy the Reader role
62sub _return_value { }
63
64no Moose::Role;
65
a7821be5 661;