X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=quotesite.git;a=blobdiff_plain;f=quotesite%2FBase.pm;h=ebd65c3ede537a7e805480af79dfc9f95dcf506e;hp=f0fa43945d03e5a1e11a149e16d634a2f349cb66;hb=a5457541076766804405416fb653592932c688ec;hpb=efd2a46770962a8ecf55e18c819b7c52042456d4 diff --git a/quotesite/Base.pm b/quotesite/Base.pm index f0fa439..ebd65c3 100644 --- a/quotesite/Base.pm +++ b/quotesite/Base.pm @@ -1,9 +1,11 @@ # (c) 2007 by Ralf Ertzinger # licensed under GNU GPL v2 -package Base; +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;