git://git.camperquake.de
/
quotesite.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c403344
)
Base: add simple_get() and ua() functions
author
Ralf Ertzinger
<ralf@skytale.net>
Thu, 15 Aug 2013 14:44:27 +0000
(16:44 +0200)
committer
Ralf Ertzinger
<ralf@skytale.net>
Thu, 15 Aug 2013 14:44:27 +0000
(16:44 +0200)
quotesite/Base.pm
patch
|
blob
|
history
diff --git
a/quotesite/Base.pm
b/quotesite/Base.pm
index
ccbb657
..
ebd65c3
100644
(file)
--- a/
quotesite/Base.pm
+++ b/
quotesite/Base.pm
@@
-4,6
+4,8
@@
package quotesite::Base;
use strict;
package quotesite::Base;
use strict;
+use LWP::UserAgent;
+use HTTP::Cookies;
use Data::Dumper;
sub new {
use Data::Dumper;
sub new {
@@
-170,4
+172,30
@@
sub setdebug {
$self->{'_DEBUG'} = shift;
}
$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;
1;