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

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

Added USerAgent::RequestHeader? to add arbitrary HTTP request header to User-Agent.
Tweaked POD for AuthenRequest?.

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