[Dbix-class] Improved resultset iterators
Toby Corkindale
toby.corkindale at strategicdata.com.au
Thu Apr 22 06:09:23 GMT 2010
Hey all,
Wouldn't it be nice if the ResultSet iterators were a bit more advanced?
I would love it if the iterator built into DBIx::Class supported some
more functional programming style methods.
ie. So that I could do:
$schema->resultset('Users')->search(
{ first_name => 'Bob' }
)->foreach(
sub { email_user($_) }
);
Or to "map" to get the results I want in one hit:
my @uppercase_names = $schema->resultset('Users')->search(
{ first_name => 'Bob' }
)->map(
sub { uc($_->last_name . $_->firstname) }
);
Or do a more complex check, grep style, to filter the list:
my @y_users = $schema->resultset('Users')->search(
{ first_name => 'Bob' }
)->grep(
sub { return complex_check($_) }
);
I realise these examples are a bit contrived, and in some cases could
be re-done with more complex SQL queries, but I thought I'd put the
suggestion out there..
-Toby
More information about the DBIx-Class
mailing list