[Jifty-commit] r7399 - Jifty-DBI/trunk/lib/Jifty/DBI

Jifty commits jifty-commit at lists.jifty.org
Sun Aug 16 18:18:34 EDT 2009


Author: sartak
Date: Sun Aug 16 18:18:33 2009
New Revision: 7399

Modified:
   Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm

Log:
Add gugud's Collection->each method from http://gugod.org/2009/08/extend-any-classes.html

Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm	Sun Aug 16 18:18:33 2009
@@ -2182,6 +2182,31 @@
     );
 }
 
+=head2 each CALLBACK
+
+Executes the callback for each item in the collection. The callback receives as
+arguments each record, its zero-based index, and the collection. The return
+value of C<each> is the original collection.
+
+If the callback returns zero, the iteration ends.
+
+=cut
+
+sub each {
+    my $self = shift;
+    my $cb   = shift;
+
+    my $idx = 0;
+    $self->goto_first_item;
+
+    while (my $record = $self->next) {
+        $cb->($record, $idx++, $self);
+        last if defined($ret) && !$ret;
+    }
+
+    return $self;
+}
+
 1;
 __END__
 


More information about the Jifty-commit mailing list