X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=blobdiff_plain;f=lib%2FCatalyst%2FController%2FDBIC%2FAPI%2FRequestArguments.pm;fp=lib%2FCatalyst%2FController%2FDBIC%2FAPI%2FRequestArguments.pm;h=5dedb28e9f3795bd4003cf8b456e102bcb57be9a;hp=f85a4e2f625cd91507c9ff979ea59a29b686b15b;hb=3300302344139421414886ed813a5376e8ff42ee;hpb=c9b8a7980c40fed5f81423f48a2c369f81348ce7 diff --git a/lib/Catalyst/Controller/DBIC/API/RequestArguments.pm b/lib/Catalyst/Controller/DBIC/API/RequestArguments.pm index f85a4e2..5dedb28 100644 --- a/lib/Catalyst/Controller/DBIC/API/RequestArguments.pm +++ b/lib/Catalyst/Controller/DBIC/API/RequestArguments.pm @@ -90,6 +90,20 @@ page is what page to return while paging predicate => 'has_page', ); +=attribute_public offset is ro, isa: Int + +offset specifies where to start the paged result (think SQL LIMIT) + +=cut + + has 'offset' => + ( + is => 'ro', + writer => '_set_offset', + isa => Int, + predicate => 'has_offset', + ); + =attribute_public ordered_by is: ro, isa: L ordered_by is passed to ->search to determine sorting @@ -460,6 +474,7 @@ request_data holds the raw (but deserialized) data for ths request $self->_set_search($new->{$controller->search_arg}) if exists $new->{$controller->search_arg}; $self->_set_count($new->{$controller->count_arg}) if exists $new->{$controller->count_arg}; $self->_set_page($new->{$controller->page_arg}) if exists $new->{$controller->page_arg}; + $self->_set_offset($new->{$controller->offset_arg}) if exists $new->{$controller->offset_arg}; } ); @@ -562,10 +577,20 @@ This builder method generates the search attributes as => $self->as || ((scalar(@{$static->as})) ? $static->as : undef), prefetch => $self->prefetch || $static->prefetch || undef, rows => $self->count || $static->count, - page => $self->page, + offset => $self->offset, join => $self->build_joins, }; + if($self->has_page) + { + $search_attributes->{page} = $self->page; + } + elsif(!$self->has_page && defined($search_attributes->{offset}) && defined($search_attributes->{rows})) + { + $search_attributes->{page} = $search_attributes->{offset} / $search_attributes->{rows} + 1; + } + + $search_attributes = { map { @$_ }