Merge branch 'master' of ssh://git.camperquake.de:22003/quotesite
[quotesite.git] / quotesite / Base.pm
index ccbb657..ebd65c3 100644 (file)
@@ -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;