semifor / Net-Twitter

A Perl interface to the Twitter APIs
83 stars 37 forks source link

warnings with Moose 2.2004 #70

Closed karenetheridge closed 7 years ago

karenetheridge commented 7 years ago

The latest Moose now contains more checks for overwriting internal methods, and now Net::Twitter warns...

(newlines added for readability)

perl -MNet::Twitter -wle'print Net::Twitter->new(traits => ["API::RESTv1_1", "OAuth"], consumer_key => 123, consumer_secret => 456, ssl => 1)'
You are overwriting a accessor (request_token_url) for the request_token_url attribute
(defined at .../Net/Twitter/Role/OAuth.pm line 43) with a new reader method for the
request_token_url attribute (defined at .../Net/Twitter/Role/OAuth.pm line 43) at
.../Moose/Meta/Attribute.pm line 1096, <DATA> line 1.
karenetheridge commented 7 years ago

This could be solved (albeit by making these attribute accesses a bit slower) with this patch to Net/Twitter/Role/OAuth.pm:

  # url attributes
  for my $attribute ( qw/authentication_url authorization_url request_token_url access_token_url xauth_url/ ) {
      has $attribute => (
          isa    => 'Str', is => 'rw', required => 1,
-         # inflate urls to URI objects when read
-         reader => { $attribute => sub { URI->new(shift->{$attribute}) } },
      );
+      # inflate urls to URI objects when read
+      around $attribute => sub {
+          my ($orig, $self) = (shift, shift);
+          return @_ ? $self->$orig(@_) : URI->new($self->$orig);
+      };
  }
karenetheridge commented 7 years ago

@perigrin points out that if you were overwriting the reader like that before, htf could the writer ever work? you're replacing it with a read-only version.

Do these attributes really need to be writable? is this tested anywhere?