root/trunk/plagger/lib/Plagger/UserAgent.pm

Revision 810 (checked in by miyagawa, 14 years ago)
  • added Plagger::Mechanize for a wrapper class around WWW::Mech (to set User-Agent from global config)
  • Updated plugins to use Plagger::Mechanize where WWW::Mech was used.
  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::UserAgent;
2 use strict;
3 use base qw( LWP::UserAgent );
4
5 use Plagger::Cookies;
6 use URI::Fetch 0.06;
7
8 sub new {
9     my $class = shift;
10     my $self  = $class->SUPER::new();
11
12     my $conf = Plagger->context->conf->{user_agent};
13     if ($conf->{cookies}) {
14         $self->cookie_jar( Plagger::Cookies->create($conf->{cookies}) );
15     }
16
17     $self->agent( $conf->{agent} || "Plagger/$Plagger::VERSION (http://plagger.org/)" );
18     $self->timeout( $conf->{timeout} || 15 );
19
20     $self;
21 }
22
23 sub fetch {
24     my($self, $url, $plugin) = @_;
25
26     URI::Fetch->fetch($url,
27         UserAgent => $self,
28         $plugin ? (Cache => $plugin->cache) : (),
29         ForceResponse => 1,
30     );
31 }
32
33 1;
34
Note: See TracBrowser for help on using the browser.