- if( $method ne 'post' ) { # force query build on POST
- my $link = $self->_get_link( $direction );
- return $self->parent->do_search( $link, $method ) if $link;
- }
-
- my $template = $self->parent->description->get_best_url;
- my( $param, $query );
- if( $method eq 'post' ) {
- my $uri = URI->new( 'http://foo.com/?' . $request->content );
- $query = { $uri->query_form };
- }
- else {
- $query = { $self->request->uri->query_form };
- }
-
- if( $param = $template->macros->{ startPage } ) {
- $query->{ $param } = $pager->$pagermethod
- }
- elsif( $param = $template->macros->{ startIndex } ) {
- if( $query->{ $param } ) {
- $query->{ $param } = $direction eq 'previous'
- ? $query->{ $param } -= $pager->entries_per_page
- : $query->{ $param } += $pager->entries_per_page;
- }
- else {
- $query->{ $param } = $direction eq 'previous'
- ? 1
- : $pager->entries_per_page + 1;
+ my $params;
+ my $osu = $self->request->opensearch_url;
+
+# this code is too fragile -- deparse depends on the order of query
+# params and the like. best just to use the last query params and
+# do the paging from there.
+#
+# if( lc $osu->method ne 'post' ) { # force query build on POST
+# my $link = $self->_get_link( $direction );
+# if( $link ) {
+# $params = $osu->deparse( $link );
+# }
+# }
+
+ # rebuild the query
+ if( !$params ) {
+ $params = $self->request->opensearch_params;
+
+ # handle paging via a page #
+ $params->{ startPage } = $page;
+
+ # handle paging via an index
+ if( exists $params->{ startIndex } ) {
+ # start index is pre-existing
+ if( $params->{ startIndex } ) {
+ if( $direction eq 'previous' ) {
+ $params->{ startIndex } -= $pager->entries_per_page
+ }
+ else {
+ $params->{ startIndex } += $pager->entries_per_page;
+ }
+ }
+ # start index did not exist previously
+ else {
+ if( $direction eq 'previous' ) {
+ $params->{ startIndex } = 1
+ }
+ else {
+ $params->{ startIndex } = $pager->entries_per_page + 1;
+ }
+
+ }