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