TaskPipe/UserAgentManager/UserAgentHandler.pm

filter: Statementstmt 41.1% 14 / 34 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 28.5% 2 / 7 Podpod 0.0% 0 / 3 totaltotal 36.3% 16 / 44 CC 2 SCAR 10.1
CC
2
Cov
41%
build_ua
6.0
__ANON__
2.0
__ANON__
2.0
CRAP 2.8
« TaskPipe/Iterator_Array.pm ↑ Summary TaskPipe/RunInfo.pm »
1 package TaskPipe::UserAgentManager::UserAgentHandler;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Module::Runtime 'require_module';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 with 'MooseX::ConfigCascade';
6 1 with 'TaskPipe::Role::MooseType_UserAgentType';
7  
8 has settings => (is => 'ro', isa => __PACKAGE__.'::Settings', default => sub{
9 0 ▶ my $module = __PACKAGE__.'::Settings';
Subroutine __ANON__: not called CC=1 SCAR=6.9
10 0 require_module( $module );
11 0 $module->new;
12 1 });
13  
14 1 has ua => (is => 'rw', isa => 'UserAgentType', lazy => 1, builder => 'build_ua');
15 1 has gm => (is => 'rw', isa => 'TaskPipe::SchemaManager');
16 has run_info => (is => 'rw', isa => 'TaskPipe::RunInfo', default => sub{
17 0 ▶ TaskPipe::RunInfo->new;
Subroutine __ANON__: not called CC=1 SCAR=6.9
18 1 });
19  
20  
21  
22  
23 sub build_ua{
24 0 ▶ my $self = shift;
Subroutine build_ua: not called CC=2 SCAR=17.9
Pod undocumented
25  
26 0 my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 } );
27 0 $ua->cookie_jar( {} );
28 0 $ua->agent( $self->settings->agent );
29 0 $ua->timeout( $self->settings->timeout );
30 0 foreach my $header_name ( %{$self->settings->headers} ){
31 0 $ua->default_header($header_name => $self->settings->headers->{$header_name} );
32 }
33  
34 0 return $ua;
35 }
36  
37 sub call{
38 0 ▶ my ($self,$method,@params) = @_;
Subroutine call: not called CC=1 SCAR=6.9
Pod undocumented
39  
40 0 my $logger = Log::Log4perl->get_logger;
41 0 $self->clear_cookies;
42 0 my $resp = $self->ua->$method(@params);
43  
44 0 return $resp;
45 }
46  
47  
48  
49 sub clear_cookies{
50 0 ▶ my ($self) = @_;
Subroutine clear_cookies: not called CC=1 SCAR=6.9
Pod undocumented
51  
52 0 $self->ua->cookie_jar({});
53 }
54  
55 =head1 NAME
56  
57 TaskPipe::UserAgentManager::UserAgentHandler - standard useragent handler
58  
59 =head1 DESCRIPTION
60  
61 This is the base useragent handler module, which defines the useragent. You can tell L<TaskPipe::Task_Scrape> to use this module, by specifying
62  
63 ua_handler_module: TaskPipe::UserAgentManager::UserAgentHandler
64  
65 in the L<TaskPipe::Task_Scrape::Settings> section of the project config
66  
67 =head1 AUTHOR
68  
69 Tom Gracey <tomgracey@gmail.com>
70  
71 =head1 COPYRIGHT AND LICENSE
72  
73 Copyright (c) Tom Gracey 2018
74  
75 TaskPipe is free software, licensed under
76  
77 The GNU Public License Version 3
78  
79 =cut
80  
81 1 __PACKAGE__->meta->make_immutable;
82 1 1;
« TaskPipe/Iterator_Array.pm ↑ Summary TaskPipe/RunInfo.pm »