Commit | Line | Data |
a7821be5 |
1 | package Moose::Meta::Method::Accessor::Native::Array::natatime; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
88e88a7b |
6 | use List::MoreUtils (); |
7 | use Params::Util (); |
a7821be5 |
8 | |
f4b86ac0 |
9 | our $VERSION = '1.16'; |
a7821be5 |
10 | $VERSION = eval $VERSION; |
11 | our $AUTHORITY = 'cpan:STEVAN'; |
12 | |
8b9641b8 |
13 | use Moose::Role; |
14 | |
15 | with '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 | |
26 | sub _minimum_arguments {1} |
27 | |
28 | sub _maximum_arguments {2} |
29 | |
30 | sub _inline_check_arguments { |
31 | my $self = shift; |
32 | |
33 | return $self->_inline_throw_error( |
e3181911 |
34 | q{'The n value passed to natatime must be an integer'}) |
a7821be5 |
35 | . ' unless defined $_[0] && $_[0] =~ /^\\d+$/;' . "\n" |
36 | . $self->_inline_throw_error( |
e3181911 |
37 | q{'The second argument passed to natatime must be a code reference'}) |
88e88a7b |
38 | . q{ if @_ == 2 && ! Params::Util::_CODELIKE( $_[1] );}; |
a7821be5 |
39 | } |
40 | |
41 | sub _inline_return_value { |
42 | my ( $self, $slot_access ) = @_; |
43 | |
44 | return |
45 | "my \$iter = List::MoreUtils::natatime( \$_[0], \@{ $slot_access } );" |
46 | . "\n" |
47 | . 'if ( $_[1] ) {' . "\n" |
48 | . 'while (my @vals = $iter->()) {' . "\n" |
49 | . '$_[1]->(@vals);' . "\n" . '}' . "\n" |
50 | . '} else {' . "\n" |
51 | . 'return $iter;' . "\n" . '}'; |
52 | } |
53 | |
8b9641b8 |
54 | # Not called, but needed to satisfy the Reader role |
55 | sub _return_value { } |
56 | |
57 | no Moose::Role; |
58 | |
a7821be5 |
59 | 1; |