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

Revision 1254 (checked in by miyagawa, 14 years ago)

move AuthenRequest? hook to useragent.init

Line 
1 package Plagger::Plugin::UserAgent::AuthenRequest;
2 use strict;
3 use warnings;
4 use base qw/Plagger::Plugin/;
5
6 use LWP::UserAgent;
7 use List::Util qw/first/;
8
9 sub register {
10     my($self, $context) = @_;
11     $context->register_hook(
12         $self,
13         'useragent.init' => \&add_credentials,
14     );
15 }
16
17 sub add_credentials {
18     my($self, $context, $args) = @_;
19
20     my $creds = $self->conf->{credentials} || [ $self->conf ];
21
22     for my $auth (@$creds) {
23         $context->log(info => "Adding credential to $auth->{realm} at $auth->{host}");
24         $args->{ua}->credentials($auth->{host}, $auth->{realm}, $auth->{username}, $auth->{password});
25     }
26 }
27
28 1;
29
30 __END__
31
32 =head1 NAME
33
34 Plagger::Plugin::UserAgent::AuthenRequest - Plagger plugin for authen request
35
36 =head1 SYNOPSYS
37
38   - module: UserAgent::AuthenRequest
39     config:
40       host: example.com:80
41       auth: basic
42       realm: Security Area
43       username: username
44       password: password
45
46 =head1 DESCRIPTION
47
48 This plugin hooks Plagger::UserAgent fetch method to add username and
49 password to authenticated website. Since it hooks Plagger::UserAgent,
50 the config will be enabled in all plugins that uses Plagger::UserAgent
51 inside, e.g. from Aggregator::Simple to Publish::MT.
52
53 =head1 AUTHOR
54
55 Daisuke Murase <typester@cpan.org>
56
57 =head1 SEE ALSO
58
59 L<Plagger>
60
61 =cut
Note: See TracBrowser for help on using the browser.