Skip to content

Commit

Permalink
Allow users to provide an LWP::UserAgent based browser.
Browse files Browse the repository at this point in the history
  • Loading branch information
oalders committed Dec 3, 2015
1 parent 8b68e2f commit 72e9f1b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ WriteMakefile(
'Carp' => 0,
'Data::Dumper' => 0,
'HTTP::Request' => 0,
'Safe::Isa' => 1.000005,
'strict' => 0,
'warnings' => 0
},
Expand Down
6 changes: 5 additions & 1 deletion lib/WebService/Instagram.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use URI;
use Carp;
use Data::Dumper;
use HTTP::Request;
use Safe::Isa;

our $VERSION = '0.05';

Expand All @@ -18,7 +19,10 @@ use constant ACCESS_TOKEN_URL => 'https://api.instagram.com/oauth/access_token?

sub new {
my ($class, $self) = @_;
$self->{browser} = LWP::UserAgent->new();
$self->{browser} ||= LWP::UserAgent->new();
unless ( $self->{browser}->$_isa('LWP::UserAgent') ) {
carp 'Browser is not a LWP::UserAgent';
}
bless $self, $class;
return $self;
}
Expand Down
17 changes: 17 additions & 0 deletions t/01-browser.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package MyUserAgent;

use base 'LWP::UserAgent';

1;
package main;

use Test::More;

use WebService::Instagram;
my $instagram = WebService::Instagram->new( {browser => MyUserAgent->new });

isa_ok( $instagram->{browser}, 'MyUserAgent' );
use DDP;
p $instagram;

done_testing;

0 comments on commit 72e9f1b

Please sign in to comment.