Commit | Line | Data |
f2fef590 |
1 | package Reaction::UI::WidgetClass::_OVER; |
2 | |
3 | use Reaction::Class; |
4 | |
5 | class _OVER, which { |
6 | |
7 | has 'collection' => (is => 'ro', required => 1); |
8 | |
9 | implements BUILD => as { |
10 | my ($self, $args) = @_; |
11 | my $coll = $args->{collection}; |
12 | unless (ref $coll eq 'ARRAY' || (blessed($coll) && $coll->can('next'))) { |
13 | confess _OVER."->new collection arg ${coll} is neither" |
14 | ." arrayref nor implements next()"; |
15 | } |
16 | }; |
17 | |
18 | implements 'each' => as { |
19 | my ($self, $do) = @_; |
20 | my $coll = $self->collection; |
21 | if (ref $coll eq 'ARRAY') { |
22 | foreach my $el (@$coll) { |
23 | $do->($el); |
24 | } |
25 | } else { |
26 | $coll->reset if $coll->can('reset'); |
27 | while (my $el = $coll->next) { |
28 | $do->($el); |
29 | } |
30 | } |
31 | }; |
32 | }; |
33 | |
34 | 1; |