X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=quotesite.git;a=blobdiff_plain;f=quotesite%2FBase.pm;fp=quotesite%2FBase.pm;h=ebd65c3ede537a7e805480af79dfc9f95dcf506e;hp=ccbb657b20ee74bfb5bef5bd7b7068ece753c01d;hb=87482e72603201424440b68d760b59e573b8eafd;hpb=18eb17221c111a8442538c54d2527e8c06b25803 diff --git a/quotesite/Base.pm b/quotesite/Base.pm index ccbb657..ebd65c3 100644 --- a/quotesite/Base.pm +++ b/quotesite/Base.pm @@ -4,6 +4,8 @@ package quotesite::Base; use strict; +use LWP::UserAgent; +use HTTP::Cookies; use Data::Dumper; sub new { @@ -170,4 +172,30 @@ sub setdebug { $self->{'_DEBUG'} = shift; } +sub ua { + my $self = shift; + my $ua; + + $ua = LWP::UserAgent->new( + 'agent' => 'Mozilla/5.0', + 'cookie_jar' => HTTP::Cookies->new, + 'timeout' => 15, + ); + + $self->{_CACHED_UA} = $ua; + + return $ua; +} + +sub simple_get { + my $self = shift; + my $url = shift; + my $ua = shift || $self->ua(); + my $r; + + $r = $ua->get($url); + return $r->decoded_content() if $r->is_success(); + return undef; +} + 1;