This repository was archived by the owner on Apr 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Trait idea: cursors #17
Copy link
Copy link
Open
Description
Hi there! I was thinking about implementing a new trait, and I wanted to see if you had any feedback on its design and whether it would be appropriate for inclusion with Twitter::API or it should be its own standalone thing.
Basically, there are two things that I don't like about working with the Twitter API (not this module in particular - it's great! Just the API in general):
- Different REST endpoints have different ways of paging through results; some use a
next_cursor/cursorsystem, some usesince_idandmax_id. - I rather dislike this pattern:
my $tw = Twitter::API->new(...);
my $max_id;
while(1) {
my $favorites = $tw->favorites({
(defined($max_id) ? (max_id => $max_id - 1) : ()),
});
last unless @$favorites;
# process $favorites here...
$max_id = min(map { $_->{'id'} } @$favorites);
}I would much rather write code like this, which is more concise and less error prone:
my $tw = Twitter::API->new(...);
my $favorites = $tw->favorites;
while(my $tweet = $favorites->next) {
# process $tweet here...
}
# alternatively, you could call $favorites->all to return a list of all favoritesThe $favorites value would be a cursor object that you could use above, but could still be an array reference so that it's backwards compatible with traditional usage. What do you think?
Metadata
Metadata
Assignees
Labels
No labels