more cleanups
[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
245478d5 9our $VERSION = '1.19';
a7821be5 10$VERSION = eval $VERSION;
11our $AUTHORITY = 'cpan:STEVAN';
12
8b9641b8 13use Moose::Role;
14
15with 'Moose::Meta::Method::Accessor::Native::Reader' => {
16 -excludes => [
17 qw(
18 _minimum_arguments
19 _maximum_arguments
20 _inline_check_arguments
21 _inline_return_value
22 )
23 ]
24};
a7821be5 25
1e2c801e 26sub _minimum_arguments { 1 }
a7821be5 27
1e2c801e 28sub _maximum_arguments { 2 }
a7821be5 29
30sub _inline_check_arguments {
31 my $self = shift;
32
53a4677c 33 return (
34 'if (!defined($_[0]) || $_[0] !~ /^\d+$/) {',
35 $self->_inline_throw_error(
36 '"The n value passed to natatime must be an integer"',
37 ) . ';',
38 '}',
39 'if (@_ == 2 && !Params::Util::_CODELIKE($_[1])) {',
40 $self->_inline_throw_error(
41 '"The second argument passed to natatime must be a code '
42 . 'reference"',
43 ) . ';',
44 '}',
45 );
a7821be5 46}
47
48sub _inline_return_value {
53a4677c 49 my $self = shift;
50 my ($slot_access) = @_;
51
52 return (
53 'my $iter = List::MoreUtils::natatime($_[0], @{ (' . $slot_access . ') });',
54 'if ($_[1]) {',
55 'while (my @vals = $iter->()) {',
56 '$_[1]->(@vals);',
57 '}',
58 '}',
59 'else {',
60 'return $iter;',
61 '}',
62 );
a7821be5 63}
64
8b9641b8 65# Not called, but needed to satisfy the Reader role
66sub _return_value { }
67
68no Moose::Role;
69
a7821be5 701;