| 1 | package WWW::Crawler::Mojo::UserAgent; | ||||||||||||
| 2 | 8 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 8 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 8 | ▶ | use Mojo::Base 'Mojo::UserAgent'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 1 | ▶ | has credentials => sub {{}}; | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 8 | has keep_credentials => 1; | |||||||||||
| 8 | |||||||||||||
| 9 | sub new { | ||||||||||||
| 10 | 2 | ▶ | my $class = shift; | ||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 11 | 2 | my $self = $class->SUPER::new(@_); | |||||||||||
| 12 | |||||||||||||
| 13 | 2 | ▶ | if ($self->keep_credentials) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 14 | $self->on(start => sub { | ||||||||||||
| 15 | 5 | ▶ | my ($self, $tx) = @_; | ||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| |||||||||||||
| 16 | 5 | my $url = $tx->req->url; | |||||||||||
| 17 | 5 | ▶ | if ($url->is_abs) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 18 | 5 | ▶ | my $key = $url->scheme. '://'. $url->host. ':'. ($url->port || 80); | ||||||||||
|
Condition50%1/2
$url->port || 80
MC/DC0%0/1
$url->port || 80
$url->port
Truth table50%1/2
A
A= $url->port
| |||||||||||||
| 19 | 5 | ▶ | if ($url->userinfo) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 20 | 2 | $self->credentials->{$key} = $url->userinfo; | |||||||||||
| 21 | } else { | ||||||||||||
| 22 | 3 | $url->userinfo($self->credentials->{$key}); | |||||||||||
| 23 | } | ||||||||||||
| 24 | } | ||||||||||||
| 25 | 2 | }); | |||||||||||
| 26 | } | ||||||||||||
| 27 | |||||||||||||
| 28 | 2 | return $self; | |||||||||||
| 29 | } | ||||||||||||
| 30 | |||||||||||||
| 31 | 8 | 1; | |||||||||||
| 32 | |||||||||||||
| 33 | =head1 NAME | ||||||||||||
| 34 | |||||||||||||
| 35 | WWW::Crawler::Mojo::UserAgent - Mojo::UserAgent sub class for userinfo storage | ||||||||||||
| 36 | |||||||||||||
| 37 | =head1 SYNOPSIS | ||||||||||||
| 38 | |||||||||||||
| 39 | my $ua = WWW::Crawler::Mojo::UserAgent->new; | ||||||||||||
| 40 | $ua->keep_credentials(1); | ||||||||||||
| 41 | $ua->credentials->{'http://example.com:80'} = 'jamadam:password'; | ||||||||||||
| 42 | my $tx = $ua->get('http://example.com/'); | ||||||||||||
| 43 | say $tx->req->url # http://jamadam:passowrd@example.com/ | ||||||||||||
| 44 | |||||||||||||
| 45 | =head1 DESCRIPTION | ||||||||||||
| 46 | |||||||||||||
| 47 | This class inherits Mojo::UserAgent and override start method for storing user | ||||||||||||
| 48 | info | ||||||||||||
| 49 | |||||||||||||
| 50 | =head1 ATTRIBUTES | ||||||||||||
| 51 | |||||||||||||
| 52 | WWW::Crawler::Mojo::UserAgent inherits all attributes from Mojo::UserAgent. | ||||||||||||
| 53 | |||||||||||||
| 54 | =head2 keep_credentials | ||||||||||||
| 55 | |||||||||||||
| 56 | Set true to set the feature on. | ||||||||||||
| 57 | |||||||||||||
| 58 | $ua->keep_credentials(1); | ||||||||||||
| 59 | |||||||||||||
| 60 | =head2 credentials | ||||||||||||
| 61 | |||||||||||||
| 62 | Storage for credentials. | ||||||||||||
| 63 | |||||||||||||
| 64 | $ua->credentials->{'http://example.com:80'} = 'jamadam:password'; | ||||||||||||
| 65 | |||||||||||||
| 66 | =head1 METHODS | ||||||||||||
| 67 | |||||||||||||
| 68 | WWW::Crawler::Mojo::UserAgent inherits all methods from Mojo::UserAgent. | ||||||||||||
| 69 | |||||||||||||
| 70 | =head1 AUTHOR | ||||||||||||
| 71 | |||||||||||||
| 72 | Sugama Keita, E<lt>sugama@jamadam.comE<gt> | ||||||||||||
| 73 | |||||||||||||
| 74 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 75 | |||||||||||||
| 76 | Copyright (C) Sugama Keita. | ||||||||||||
| 77 | |||||||||||||
| 78 | This program is free software; you can redistribute it and/or | ||||||||||||
| 79 | modify it under the same terms as Perl itself. | ||||||||||||
| 80 | |||||||||||||
| 81 | =cut | ||||||||||||