aboutsummaryrefslogtreecommitdiffstats
path: root/lib/WWW/StrawViewer.pm
diff options
context:
space:
mode:
authortrizen <trizen@protonmail.com>2020-02-27 08:31:20 +0200
committertrizen <trizen@protonmail.com>2020-02-27 08:31:20 +0200
commit3bb78645fd553b3d58b222931c4828e373cc49c3 (patch)
tree673d629ff8f876279e74d61250252daa0d8a6a78 /lib/WWW/StrawViewer.pm
parent1659520ed4f2bf9a3039a5c59218fa32fddb6580 (diff)
downloadfair-viewer-3bb78645fd553b3d58b222931c4828e373cc49c3.tar.lz
fair-viewer-3bb78645fd553b3d58b222931c4828e373cc49c3.tar.xz
fair-viewer-3bb78645fd553b3d58b222931c4828e373cc49c3.zip
- Added support for next pages of results. (fixes https://github.com/trizen/straw-viewer/issues/1)
Diffstat (limited to 'lib/WWW/StrawViewer.pm')
-rw-r--r--lib/WWW/StrawViewer.pm47
1 files changed, 29 insertions, 18 deletions
diff --git a/lib/WWW/StrawViewer.pm b/lib/WWW/StrawViewer.pm
index 99331d5..5f0ae02 100644
--- a/lib/WWW/StrawViewer.pm
+++ b/lib/WWW/StrawViewer.pm
@@ -271,7 +271,7 @@ sub set_lwp_useragent {
$self->{lwp} = $lwp->new(
- cookie_jar => {}, # temporary cookies
+ cookie_jar => {}, # temporary cookies
timeout => $self->get_lwp_timeout,
show_progress => $self->get_debug,
agent => $self->get_lwp_agent,
@@ -998,26 +998,37 @@ sub post_as_json {
$self->_save('POST', $url, $json_str);
}
-# SUBROUTINE FACTORY
-{
- no strict 'refs';
+sub next_page {
+ my ($self, $url) = @_;
- # Create {next,previous}_page subroutines
- foreach my $name ('next_page', 'previous_page') {
- *{__PACKAGE__ . '::' . $name} = sub {
- my ($self, $url, $token) = @_;
+ my $pt_url = (
+ $url =~ s{[?&]page=\K(\d+)}{$1+1}e
+ ? $url
+ : $self->_append_url_args($url, page => 2)
+ );
- my $pt_url = (
- $url =~ s/[?&]pageToken=\K[^&]+/$token/
- ? $url
- : $self->_append_url_args($url, pageToken => $token)
- );
+ my $res = $self->_get_results($pt_url);
+ $res->{url} = $pt_url;
+ return $res;
+}
- my $res = $self->_get_results($pt_url);
- $res->{url} = $pt_url;
- return $res;
- };
- }
+sub previous_page {
+ my ($self, $url) = @_;
+
+ my $pt_url = (
+ $url =~ s{[?&]page=\K(\d+)}{($1 > 2) ? ($1-1) : 1}e
+ ? $url
+ : $url
+ );
+
+ my $res = $self->_get_results($pt_url);
+ $res->{url} = $pt_url;
+ return $res;
+}
+
+# SUBROUTINE FACTORY
+{
+ no strict 'refs';
# Create proxy_{exec,system} subroutines
foreach my $name ('exec', 'system', 'stdout') {