| 1 | package HTTP::Proxy::Engine; | ||||||||||||||||||||||||||||
| 2 | 67 | $HTTP::Proxy::Engine::VERSION = '0.304'; | |||||||||||||||||||||||||||
| 3 | 67 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 67 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 67 | my %engines = ( | |||||||||||||||||||||||||||
| 7 | MSWin32 => 'NoFork', | ||||||||||||||||||||||||||||
| 8 | default => 'Legacy', | ||||||||||||||||||||||||||||
| 9 | ); | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # required accessors | ||||||||||||||||||||||||||||
| 12 | 67 | __PACKAGE__->make_accessors( qw( max_clients )); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 82 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 82 | my $class = shift; | |||||||||||||||||||||||||||
| 16 | 82 | my %params = @_; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # the front-end | ||||||||||||||||||||||||||||
| 19 | 82 | ▶ | if ( $class eq 'HTTP::Proxy::Engine' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 78 | my $engine = delete $params{engine}; | |||||||||||||||||||||||||||
| 21 | $engine = $engines{$^O} || $engines{default} | ||||||||||||||||||||||||||||
| 22 | 78 | ▶ | unless defined $engine; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$engines{$^O} || $engines{'default'}
MC/DC0%0/2
$engines{$^O} || $engines{'default'}
$engines{$^O}
$engines{'default'}
Truth table33%1/3
A || B
A= $engines{$^O}B= $engines{'default'}
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 78 | $class = "HTTP::Proxy::Engine::$engine"; | |||||||||||||||||||||||||||
| 25 | 78 | eval "require $class"; | |||||||||||||||||||||||||||
| 26 | 78 | ▶ | croak $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # some error checking | ||||||||||||||||||||||||||||
| 30 | croak "No proxy defined" | ||||||||||||||||||||||||||||
| 31 | 81 | ▶ | unless exists $params{proxy}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | croak "$params{proxy} is not a HTTP::Proxy object" | ||||||||||||||||||||||||||||
| 33 | 78 | ▶ | unless UNIVERSAL::isa( $params{proxy}, 'HTTP::Proxy' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # so we are an actual engine | ||||||||||||||||||||||||||||
| 36 | 67 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | return bless { | ||||||||||||||||||||||||||||
| 38 | 76 | %{"$class\::defaults"}, | |||||||||||||||||||||||||||
| 39 | %params | ||||||||||||||||||||||||||||
| 40 | }, $class; | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # run() should be defined in subclasses | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 46 | 0 | my $class = ref $self; | |||||||||||||||||||||||||||
| 47 | 0 | croak "$class doesn't define a run() method"; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 201 | ▶ | sub proxy { $_[0]{proxy} } | ||||||||||||||||||||||||||
|
Subroutine
proxy: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # class method | ||||||||||||||||||||||||||||
| 53 | 132 | ▶ | sub make_accessors { | ||||||||||||||||||||||||||
|
Subroutine
make_accessors: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 132 | my $class = shift; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 132 | for my $attr (@_) { | |||||||||||||||||||||||||||
| 57 | 67 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 58 | 272 | ▶ | *{"$class\::$attr"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 59 | 512 | ▶ | $_[0]{$attr} = $_[1] if defined $_[1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 512 | $_[0]{$attr}; | |||||||||||||||||||||||||||
| 61 | 272 | }; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 67 | 1; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||||||||||