added action_filter
[catagits/Reaction.git] / lib / Reaction / UI / WidgetClass / _OVER.pm
CommitLineData
f2fef590 1package Reaction::UI::WidgetClass::_OVER;
2
3use Reaction::Class;
4
81393881 5use namespace::clean -except => [ qw(meta) ];
f2fef590 6
f2fef590 7
81393881 8has 'collection' => (is => 'ro', required => 1);
9sub BUILD {
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};
17sub each {
18 my ($self, $do) = @_;
19 my $coll = $self->collection;
20 if (ref $coll eq 'ARRAY') {
21 foreach my $el (@$coll) {
22 $do->($el);
f2fef590 23 }
81393881 24 } else {
25 $coll->reset if $coll->can('reset');
26 while (my $el = $coll->next) {
27 $do->($el);
f2fef590 28 }
81393881 29 }
f2fef590 30};
81393881 31__PACKAGE__->meta->make_immutable;
32
f2fef590 33
341;