| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | # Set LWP proxy | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | if( $ie_proxy_server=~/;/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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/")
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/")
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | my $iekey = $RegHash{"CUser/Software/Microsoft/Windows/CurrentVersion/Internet Settings/"} or return ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | my $ie_proxy_enable = $iekey->{"/ProxyEnable"} or return ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | my $ie_proxy_server = $iekey->{"/ProxyServer"} or return ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $ie_proxy_no = $iekey->{"/ProxyOverride"}; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | $_[1]=$ie_proxy_no if defined($ie_proxy_no); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | return $ie_proxy_enable=~/1$/ ? $ie_proxy_server : ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | eval 'use Win32::Registry;'; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | return "" if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | return defined($ie_proxy_enable) && $ie_proxy_enable=~/1$/ && defined($ie_proxy_server) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $ie_proxy_enable and $ie_proxy_enable =~ /1$/ and defined $ie_proxy_server
defined $ie_proxy_enable and $ie_proxy_enable =~ /1$/
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$proxy_name =~ /^No$/i or $proxy_name eq ""
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 ""
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | # Use default proxy | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | if( $proxy_name=~/^(System|Default)/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||