[jifty-devel] (un)limit negligence warnings
Jason May
jason.a.may at gmail.com
Tue Mar 18 14:43:00 EDT 2008
Hello,
I have been using Jifty, along with many other frameworks, and one issue I
have had with Jifty was forgetting to use unlimit on a collection that had
no conditions. I imagine that there are many Jifty newbies like me with the
same frustrations starting out, so I made some warnings:
Let's say I bless a MyApp::Model::PersonCollection, then I try to loop
through ->next iterations without unlimiting, the loop will not even occur.
@{ MyApp::Model::PersonCollection } will just be an empty array (though I
think _is_limited(-1) should be called if no limit has been set anyway since
that's almost 100% what the user intended in the first place...)
For now, I placed a bunch of warnings where (to my knowledge) the mistake
would be made.
Warnings in `jifty server`:
INFO - You can connect to your server at http://localhost:8888/
INFO - GET request for /
WARN - You may have wanted to use ->limit or ->unlimit on the collection at
/home/jasonmay/code/perl/jifty/MyApp/lib/MyApp/View.pm line 14
Warnings in `jifty repl`:
jasonmay at culex $ jifty repl
$ @{ MyApp::Model::PersonCollection->new }
WARN - You may have wanted to use ->limit or ->unlimit on the collection at
(eval 578) line 5
$
The patch:
Index: lib/Jifty/DBI/Collection.pm
===================================================================
--- lib/Jifty/DBI/Collection.pm (revision 5218)
+++ lib/Jifty/DBI/Collection.pm (working copy)
@@ -904,7 +904,10 @@
sub peek {
my $self = shift;
- return (undef) unless ( $self->_is_limited );
+ unless ( $self->_is_limited ) {
+ Carp::carp "You may have wanted to use ->limit or ->unlimit on
the collection";
+ return (undef);
+ }
$self->_do_search() if $self->{'must_redo_search'};
@@ -985,7 +988,10 @@
my $self = shift;
# If we're not limited, return an empty array
- return [] unless $self->_is_limited;
+ unless ($self->_is_limited) {
+ Carp::carp "You may have wanted to use ->limit or ->unlimit on the
collection";
+ return [];
+ }
# Do a search if we need to.
$self->_do_search() if $self->{'must_redo_search'};
@@ -1875,7 +1881,10 @@
my $self = shift;
# An unlimited search returns no tickets
- return 0 unless ( $self->_is_limited );
+ unless ( $self->_is_limited ) {
+ Carp::carp "You may have wanted to use ->limit or ->unlimit on the
collection";
+ return 0;
+ }
# If we haven't actually got all objects loaded in memory, we
# really just want to do a quick count from the database.
@@ -1926,7 +1935,10 @@
my $self = shift;
# An unlimited search returns no tickets
- return 0 unless ( $self->_is_limited );
+ unless ( $self->_is_limited ) {
+ Carp::carp "You may have wanted to use ->limit or ->unlimit on the
collection";
+ return 0;
+ }
# If we haven't actually got all objects loaded in memory, we
# really just want to do a quick count from the database.
Please let me know what you think.
Thanks,
Jason May
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jifty.org/pipermail/jifty-devel/attachments/20080318/a9ad2551/attachment.htm
More information about the jifty-devel
mailing list