[Jifty-commit] r4775 - in jifty/trunk: lib/Jifty/Plugin/REST
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu Dec 27 16:15:13 EST 2007
Author: sartak
Date: Thu Dec 27 16:15:12 2007
New Revision: 4775
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm
Log:
r49625 at onn: sartak | 2007-12-27 16:14:36 -0500
Add __limit/N to /=/search/ for when you really only want N results -- such as when displaying them in a dashboard widget O:)
Modified: jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm Thu Dec 27 16:15:12 2007
@@ -449,6 +449,16 @@
Will throw a 404 if there were no matches, or C<$field> was invalid.
+Pseudo-columns:
+
+=over 4
+
+=item __limit => N
+
+Limits the collection to N models.
+
+=back
+
=cut
sub search_items {
@@ -465,17 +475,33 @@
# limit to the key => value pairs they gave us
my $collection = eval { $model->collection_class->new }
or abort(404);
+ $collection->unlimit;
- # no pieces? they must be asking for everything
- if (!@pieces) {
- $collection->unlimit;
- }
+ my %special = (
+ __limit => sub {
+ my $N = shift;
+
+ # must be a number
+ $N =~ /^\d+$/
+ or abort(404);
+
+ $collection->set_page_info(
+ per_page => $N,
+ current_page => 1,
+ );
+ },
+ );
while (@pieces) {
my $column = shift @pieces;
my $value = shift @pieces;
- $collection->limit(column => $column, value => $value);
+ if (exists $special{$column}) {
+ $special{$column}->($value);
+ }
+ else {
+ $collection->limit(column => $column, value => $value);
+ }
}
$collection->count or abort(404);
More information about the Jifty-commit
mailing list