blib/lib/LWP/UserAgent/ProxyAny.pm

filter: Statementstmt 52.7% 29 / 55 Branchbran 11.1% 4 / 36 Conditioncond 8.3% 1 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 88.8% 8 / 9 Podpod 75.0% 3 / 4 totaltotal 36.5% 45 / 123 CC 23 SCAR 34.1
CC
23
Cov
33%
get_ie_proxy
57.3
get_ie_proxy_with_registry
43.1
env_proxy
18.3
CRAP 30.3
↑ Summary
1 package LWP::UserAgent::ProxyAny;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 our $VERSION = "1.01";
5 1 ▶use base qw(LWP::UserAgent);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶sub env_proxy {
Subroutine env_proxy: called CC=6 SCAR=29.1
Pod documented
8 1 my ( $this ) = @_;
9  
10 # Call real env_proxy of LWP UserAgent
11 1 $this->SUPER::env_proxy;
12  
13 # Try to get IE proxy setttings, return if not Win32 or not set
14 1 my $ie_proxy_no = "";
15 1 my $ie_proxy_server = $this->get_ie_proxy( $ie_proxy_no );
16 1 ▶ return if $ie_proxy_server eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $ie_proxy_server eq "" 1 0 1
17  
18 # Set LWP proxy
19 0 ▶ if( $ie_proxy_server=~/;/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ie_proxy_server =~ /;/) { } 0 0 0
20 #Multiple proxies, such as ftp=192.168.1.3:8080;...;https=192.168.1.3:8080
21 0 ▶ map /^(.*?)=(.*?)$/ && $this->proxy( $1, "http://$2/" ), split( /;/, $ie_proxy_server );
Condition0%0/3
/^(.*?)=(.*?)$/ && $this->proxy($1, "http://$2/")
!ll&&!rl&&r
000
MC/DC0%0/2
/^(.*?)=(.*?)$/ && $this->proxy($1, "http://$2/")
/^(.*?)=(.*?)$/ $this->proxy($1, "http://$2/")
Truth table0%0/3
A && B
A= /^(.*?)=(.*?)$/B= $this->proxy($1, "http://$2/")
ABresult
0X0
100
111
22 }else{
23 #Single proxy, such as 192.168.1.3:8080
24 0 $this->proxy( ['http','https','ftp','gopher'], "http://$ie_proxy_server/" );
25 }
26  
27 # Set LWP no_proxy
28 0 ▶ $this->no_proxy( map( /<local>/i ? "localhost" : $_, split( /;/, $ie_proxy_no ) ) )
Branch: 2 branches
BranchTrueFalseTotal
if $ie_proxy_no ne "" 0 0 0
/<local>/i ? : 0 0 0
29 if $ie_proxy_no ne "";
30 }
31  
32 2 ▶sub get_ie_proxy {
Subroutine get_ie_proxy: called CC=8 SCAR=40.5
Pod documented
33 2 ▶ return "" unless $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $^O eq "MSWin32" 2 0 2
34 0 my %RegHash;
35 0 eval 'use Win32::TieRegistry(Delimiter=>"/", TiedHash=>\%RegHash);';
36 0 ▶ return get_ie_proxy_with_registry() if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
37 0 ▶ my $iekey = $RegHash{"CUser/Software/Microsoft/Windows/CurrentVersion/Internet Settings/"} or return "";
Branch: 1 branch
BranchTrueFalseTotal
my $iekey = $RegHash{"CUser/Software/Microsoft/Windows/CurrentVersion/Internet Settings/"} or return "" 0 0 0
38 0 ▶ my $ie_proxy_enable = $iekey->{"/ProxyEnable"} or return "";
Branch: 1 branch
BranchTrueFalseTotal
my $ie_proxy_enable = $iekey->{"/ProxyEnable"} or return "" 0 0 0
39 0 ▶ my $ie_proxy_server = $iekey->{"/ProxyServer"} or return "";
Branch: 1 branch
BranchTrueFalseTotal
my $ie_proxy_server = $iekey->{"/ProxyServer"} or return "" 0 0 0
40 0 my $ie_proxy_no = $iekey->{"/ProxyOverride"};
41 0 ▶ $_[1]=$ie_proxy_no if defined($ie_proxy_no);
Branch: 1 branch
BranchTrueFalseTotal
if defined $ie_proxy_no 0 0 0
42 0 ▶ return $ie_proxy_enable=~/1$/ ? $ie_proxy_server : "";
Branch: 1 branch
BranchTrueFalseTotal
$ie_proxy_enable =~ /1$/ ? : 0 0 0
43 }
44  
45 0 ▶sub get_ie_proxy_with_registry {
Subroutine get_ie_proxy_with_registry: not called CC=8 SCAR=37.6
Pod undocumented
46 0 ▶ return "" unless $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $^O eq "MSWin32" 0 0 0
47 0 eval 'use Win32::Registry;';
48 0 ▶ return "" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
49 0 my ( $iekey, $type, $ie_proxy_enable, $ie_proxy_server, $ie_proxy_no );
50 1 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 0 ▶ $::HKEY_CURRENT_USER->Open( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", $iekey ) or return "";
Branch: 1 branch
BranchTrueFalseTotal
$main::HKEY_CURRENT_USER->Open("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", $iekey) or return "" 0 0 0
52 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 0 $iekey->QueryValueEx( "ProxyEnable", $type, $ie_proxy_enable );
54 0 $iekey->QueryValueEx( "ProxyServer", $type, $ie_proxy_server );
55 0 $iekey->QueryValueEx( "ProxyOverride", $type, $ie_proxy_no );
56 0 $iekey->Close;
57 0 ▶ $_[1]=$ie_proxy_no if defined($ie_proxy_no);
Branch: 1 branch
BranchTrueFalseTotal
if defined $ie_proxy_no 0 0 0
58 0 ▶ return defined($ie_proxy_enable) && $ie_proxy_enable=~/1$/ && defined($ie_proxy_server)
Branch: 1 branch
BranchTrueFalseTotal
defined $ie_proxy_enable && $ie_proxy_enable =~ /1$/ && defined $ie_proxy_server ? : 0 0 0
Condition0%0/6
defined $ie_proxy_enable and $ie_proxy_enable =~ /1$/ and defined $ie_proxy_server
!ll&&!rl&&r
000
defined $ie_proxy_enable and $ie_proxy_enable =~ /1$/
!ll&&!rl&&r
000
MC/DC0%0/3
defined $ie_proxy_enable and $ie_proxy_enable =~ /1$/ and defined $ie_proxy_server
defined $ie_proxy_enable $ie_proxy_enable =~ /1$/ defined $ie_proxy_server
Truth table0%0/4
A and B and C
A= defined $ie_proxy_enableB= $ie_proxy_enable =~ /1$/C= defined $ie_proxy_server
ABCresult
0XX0
10X0
1100
1111
59 ? $ie_proxy_server : "";
60 }
61  
62 1 ▶sub set_proxy_by_name {
Subroutine set_proxy_by_name: called CC=4 SCAR=16.1
Pod documented
63 1 my ( $this, $proxy_name ) = @_;
64 1 $proxy_name=~s/ //g; # Remove spaces
65  
66 #Don't use proxy
67 1 ▶ return if $proxy_name=~/^No$/i or $proxy_name eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $proxy_name =~ /^No$/i or $proxy_name eq "" 0 1 1
Condition33%1/3
$proxy_name =~ /^No$/i or $proxy_name eq ""
l!l&&r!l&&!r
001
MC/DC0%0/2
$proxy_name =~ /^No$/i or $proxy_name eq ""
$proxy_name =~ /^No$/i $proxy_name eq ""
Truth table33%1/3
A or B
A= $proxy_name =~ /^No$/iB= $proxy_name eq ""
ABresult
1X1
011
000
68  
69 # Use default proxy
70 1 ▶ if( $proxy_name=~/^(System|Default)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proxy_name =~ /^(System|Default)/i) 0 1 1
71 0 $this->env_proxy;
72 0 return;
73 }
74  
75 # Set user-defined proxy
76 1 $proxy_name =~ s/^http:\/\///i;
77 1 $this->proxy( ['http','https','ftp','gopher'], "http://$proxy_name" );
78 }
79  
80 1 1;
81 __END__
↑ Summary