X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=quotesite.git;a=blobdiff_plain;f=quotesite%2FBase.pm;h=ebd65c3ede537a7e805480af79dfc9f95dcf506e;hp=08897c9a86cdd006eb651483d0560890c21d8065;hb=a5457541076766804405416fb653592932c688ec;hpb=20af9b1c4f051c0830ba35b8d3d15439c499e119 diff --git a/quotesite/Base.pm b/quotesite/Base.pm index 08897c9..ebd65c3 100644 --- a/quotesite/Base.pm +++ b/quotesite/Base.pm @@ -1,14 +1,16 @@ # (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 { my $class = shift; - my $self = {'_DEBUG' => 0, '_OUT' => sub {print shift}, '_OUTSTACK' => []}; + my $self = {'_DEBUG' => 0, '_OUT' => sub {print shift}}; bless($self, $class); @@ -91,23 +93,6 @@ sub setio { $self->{'_OUT'} = $io; } -sub pushio { - my $self = shift; - my $io = shift; - - push(@{$self->{'_OUTSTACK'}}, $self->{'_OUT'}); - $self->setio($io); -} - -sub popio { - my $self = shift; - my $io = pop(@{$self->{'_OUTSTACK'}}); - - if (defined($io)) { - $self->setio($io); - } -} - sub getconfstr { my $self = shift; my $s = 'Options for ' . $self->{'NAME'} . ":\n"; @@ -187,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;