DateTime::Set in cvs:
=item * iterate
Experimental method - subject to change.
This method apply a callback subroutine to all
elements of a set.
sub callback {
$_[0]->add( hours => 1 );
}
# offset $set elements by one hour
$set->iterate( \&callback );
# $set2 elements are one hour after $set
elements, and
# $set is unchanged
$set2 = $set->clone->iterate( \&callback );
If the callback returns C<undef>, the datetime is
removed from the set:
sub remove_sundays {
$_[0] unless $_[0]->day_of_week == 7;
}
The callback can be used to postpone or anticipate
events which collide with datetimes in another set:
sub after_holiday {
$_[0]->add( days => 1 ) while
$holidays->contains( $_[0] );
}
- Flavio S. Glock