Refactored native trait accessors so they are done entirely in roles.
[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
6use List::MoreUtils;
7
10bd99ec 8our $VERSION = '1.14';
a7821be5 9$VERSION = eval $VERSION;
10our $AUTHORITY = 'cpan:STEVAN';
11
8b9641b8 12use Moose::Role;
13
14with '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};
a7821be5 24
25sub _minimum_arguments {1}
26
27sub _maximum_arguments {2}
28
29sub _inline_check_arguments {
30 my $self = shift;
31
32 return $self->_inline_throw_error(
e3181911 33 q{'The n value passed to natatime must be an integer'})
a7821be5 34 . ' unless defined $_[0] && $_[0] =~ /^\\d+$/;' . "\n"
35 . $self->_inline_throw_error(
e3181911 36 q{'The second argument passed to natatime must be a code reference'})
a7821be5 37 . q{ if defined $_[1] && ( ref $_[1] || q{} ) ne 'CODE';};
38}
39
40sub _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
8b9641b8 53# Not called, but needed to satisfy the Reader role
54sub _return_value { }
55
56no Moose::Role;
57
a7821be5 581;