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