Subject: | [Patch] Setting UserAgent |
HTML-SimpleLinkExtor should have the ability to allow people to set the
UserAgent if they want to use.
I have attached a patch that does this.
Subject: | user_agent.patch |
--- SimpleLinkExtor-orig.pm 2007-12-02 23:41:33.000000000 -0500
+++ SimpleLinkExtor.pm 2007-12-03 00:12:22.000000000 -0500
@@ -40,6 +40,10 @@
my $self = new HTML::LinkExtor;
bless $self, $class;
+ require LWP::UserAgent;
+ my $ua = LWP::UserAgent->new;
+
+ $self->{'_ua'} = $ua;
$self->{'_SimpleLinkExtor_base'} = $base;
$self->_init_links;
@@ -219,19 +223,26 @@
}
}
}
+sub user_agent {
+ my $self = shift;
+ my $user_agent = shift;
+ $self->{'_ua'}->agent($user_agent);
+}
sub parse_url
{
my $self = shift;
my $url = shift;
- require LWP::Simple;
-
- my $data = LWP::Simple::get( $url );
-
- return unless defined $data;
+ my $response = $self->{'_ua'}->get( $url );
+
+ if ($response->is_success) {
+ $self->parse( $response->content );
+ }
+ else {
+ return undef;
+ }
- $self->parse( $data );
}
1;