[Jifty-commit] r7470 - in Jifty-DBI/branches/tisql: lib/Jifty/DBI
Jifty commits
jifty-commit at lists.jifty.org
Wed Sep 2 20:55:21 EDT 2009
Author: ruz
Date: Wed Sep 2 20:55:21 2009
New Revision: 7470
Modified:
Jifty-DBI/branches/tisql/ (props changed)
Jifty-DBI/branches/tisql/lib/Jifty/DBI/Collection.pm
Jifty-DBI/branches/tisql/lib/Jifty/DBI/Record.pm
Log:
* sync from trunk
Modified: Jifty-DBI/branches/tisql/lib/Jifty/DBI/Collection.pm
==============================================================================
--- Jifty-DBI/branches/tisql/lib/Jifty/DBI/Collection.pm (original)
+++ Jifty-DBI/branches/tisql/lib/Jifty/DBI/Collection.pm Wed Sep 2 20:55:21 2009
@@ -2201,6 +2201,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) {
+ my $ret = $cb->($record, $idx++, $self);
+ last if defined($ret) && !$ret;
+ }
+
+ return $self;
+}
+
sub tisql {
my $self = shift;
require Jifty::DBI::Tisql;
Modified: Jifty-DBI/branches/tisql/lib/Jifty/DBI/Record.pm
==============================================================================
--- Jifty-DBI/branches/tisql/lib/Jifty/DBI/Record.pm (original)
+++ Jifty-DBI/branches/tisql/lib/Jifty/DBI/Record.pm Wed Sep 2 20:55:21 2009
@@ -607,17 +607,27 @@
=head2 readable_attributes
-Returns a list this table's readable columns
+Returns the list of this table's readable columns. They are first sorted so
+that primary keys come first, and then they are sorted in alphabetical order.
=cut
sub readable_attributes {
my $self = shift;
- return @{
- $self->_READABLE_COLS_CACHE() || $self->_READABLE_COLS_CACHE(
- [ sort map { $_->name } grep { $_->readable } $self->columns ]
- )
- };
+
+ my %is_primary = map { $_ => 1 } @{ $self->_primary_keys };
+
+ return @{ $self->_READABLE_COLS_CACHE() || $self->_READABLE_COLS_CACHE([
+ map { $_->name }
+ sort { do {
+ no warnings 'uninitialized';
+ ($is_primary{$b->name} <=> $is_primary{$a->name})
+ ||
+ ($a->name cmp $b->name)
+ } }
+ grep { $_->readable }
+ $self->columns
+ ])};
}
=head2 serialize_metadata
More information about the Jifty-commit
mailing list