Hello,<br><br>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:<br>
<br>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.<br>@{ 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...)<br>
<br>For now, I placed a bunch of warnings where (to my knowledge) the mistake would be made.<br><br>Warnings in `jifty server`:<br>INFO - You can connect to your server at <a href="http://localhost:8888/">http://localhost:8888/</a><br>
INFO - GET request for /<br>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<br><br>Warnings in `jifty repl`:<br>jasonmay@culex $ jifty repl<br>
$ @{ MyApp::Model::PersonCollection->new }<br>WARN - You may have wanted to use ->limit or ->unlimit on the collection at (eval 578) line 5<br>$<br><br>The patch:<br>Index: lib/Jifty/DBI/Collection.pm<br>===================================================================<br>
--- lib/Jifty/DBI/Collection.pm (revision 5218)<br>+++ lib/Jifty/DBI/Collection.pm (working copy)<br>@@ -904,7 +904,10 @@<br> sub peek {<br> my $self = shift;<br> <br>- return (undef) unless ( $self->_is_limited );<br>
+ unless ( $self->_is_limited ) {<br>+ Carp::carp "You may have wanted to use ->limit or ->unlimit on the collection";<br>+ return (undef);<br>+ }<br> <br> $self->_do_search() if $self->{'must_redo_search'};<br>
<br>@@ -985,7 +988,10 @@<br> my $self = shift;<br> <br> # If we're not limited, return an empty array<br>- return [] unless $self->_is_limited;<br>+ unless ($self->_is_limited) {<br>+ Carp::carp "You may have wanted to use ->limit or ->unlimit on the collection";<br>
+ return [];<br>+ }<br> <br> # Do a search if we need to.<br> $self->_do_search() if $self->{'must_redo_search'};<br>@@ -1875,7 +1881,10 @@<br> my $self = shift;<br> <br> # An unlimited search returns no tickets<br>
- return 0 unless ( $self->_is_limited );<br>+ unless ( $self->_is_limited ) {<br>+ Carp::carp "You may have wanted to use ->limit or ->unlimit on the collection";<br>+ return 0;<br>
+ }<br> <br> # If we haven't actually got all objects loaded in memory, we<br> # really just want to do a quick count from the database.<br>@@ -1926,7 +1935,10 @@<br> my $self = shift;<br> <br> # An unlimited search returns no tickets<br>
- return 0 unless ( $self->_is_limited );<br>+ unless ( $self->_is_limited ) {<br>+ Carp::carp "You may have wanted to use ->limit or ->unlimit on the collection";<br>+ return 0;<br>
+ }<br> <br> # If we haven't actually got all objects loaded in memory, we<br> # really just want to do a quick count from the database.<br><br>Please let me know what you think.<br><br>Thanks,<br><br>Jason May<br>