Subject: | [Patch] Feature request: useragent_class argument |
I am using Net::Twitter very successfully with LWP::UserAgent::POE 0.02.
To do so, however, I have to poke at Net::Twitter's internals.
Something like:
my $twitter = Net::Twitter->new(
username => 'foo', password => 'bar'
);
$twitter->{ua} = LWP::UserAgent::POE->new;
$twitter->{ua}->credentials(
$twitter->{apihost},
$twitter->{apirealm},
$twitter->{username},
$twitter->{password},
);
With the attached patch, I would be able to:
my $twitter = Net::Twitter->new(
useragent_class => 'LWP::UserAgent::POE',
username => 'foo', password => 'bar',
);
The patch handles creation of both {ua} and {tvua} using the optional
useragent_class argument defaulting to LWP::UserAgent.
Subject: | net-twitter.patch |
diff --git a/lib/Net/Twitter.pm b/lib/Net/Twitter.pm
index d42fbe4..e9439f8 100755
--- a/lib/Net/Twitter.pm
+++ b/lib/Net/Twitter.pm
@@ -35,7 +35,11 @@ sub new {
$conf{twittervision} = '0' unless defined $conf{twittervision};
- $conf{ua} = LWP::UserAgent->new();
+ $conf{useragent_class} ||= 'LWP::UserAgent';
+ eval "use $conf{useragent_class}";
+ die $@ if $@;
+
+ $conf{ua} = $conf{useragent_class}->new();
$conf{username} = $conf{user} if defined $conf{user};
$conf{password} = $conf{pass} if defined $conf{pass};
@@ -52,7 +56,7 @@ sub new {
$conf{ua}->env_proxy();
if ( $conf{twittervision} ) {
- $conf{tvua} = LWP::UserAgent->new();
+ $conf{tvua} = $conf{useragent_class}->new();
$conf{tvua}
->credentials( $conf{tvhost}, $conf{tvrealm}, $conf{username},
$conf{password} );
@@ -700,6 +704,11 @@ REQUIRED.
OPTIONAL: Sets the User Agent header in the HTTP request. If omitted, this will default to
"Net::Twitter/$Net::Twitter::Version (Perl)"
+=item C<useragent_class>
+
+OPTIONAL: A L<LWP::UserAgent> compatible class, e.g., L<LWP::UserAgent::POE>.
+If omitted, this will default to L<LWP::UserAgent>.
+
=item C<source>
OPTIONAL: Sets the source name, so messages will appear as "from <source>" instead