Browse files

Rewrote the "duplicate keys" patch to:

a) not attempt to collapse "image" and "media" keys (documented as having arrayref args)
b) only collapse arrays with multiple copies of the same value
  • Loading branch information...
1 parent e6c591a commit f25091da6853f94cb642f5e245c03513493d1a25 @castaway committed Feb 20, 2013
Showing with 12 additions and 2 deletions.
  1. +12 −2 lib/Net/Twitter/
@@ -56,8 +56,18 @@ sub twitter_api_method {
# remove remaining duplicates:
- for ( keys %$args ) {
- $args->{$_} = $args->{$_}[0] if ref $args->{$_} eq 'ARRAY';
+ foreach my $key ( keys %$args ) {
+ next if grep { $key eq $_ } (qw/media image/);
+ if(ref $args->{$key} eq 'ARRAY') {
+ my %seen;
+ $seen{$_}++ for @{$args->{$key}};
+ if(scalar keys %seen == 1) {
+ $args->{$key} = $args->{$key}[0];
+ } else {
+ $args->{$key} = [ keys %seen ];
+ }
+ }

1 comment on commit f25091d

I'm having trouble liking this patch. :) That doesn't mean I'm rejecting it out-of-hand. I want to understand the need for it better.

I think there's yet another place it breaks. Net::Twitter accepts an arrayref for user_id and screen_name. Some methods, like lookup_users expect a comma separated list of IDs. Net::Twitter accepts an arrayref of IDs and flattens them to a comma separated list which seems more perlish to me.

In general, Net::Twitter doesn't pay much attention to the values passed in parameters. Twitter has a habit of adding (and removing) parameters with alarming frequency. With few exceptions, Net::Twitter passes whatever you give it directly through to Twitter. That allows Net::Twitter to accommodate new parameters without requiring a new release.

Perhaps this would be better handled as an optional trait in the Net::Twitter::Role:: namespace. Maybe around _perpare_request.

Please sign in to comment.