Proxy/Engine.pm

filter: Statementstmt 92.1% 35 / 38 Branchbran 100% 12 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 88.8% 8 / 9 Podpod 100% 4 / 4 totaltotal 88.2% 60 / 68 CC 9 SCAR 13.3
CC
9
Cov
91%
new
7.0
run
2.0
make_accessors
2.0
CRAP 3.8
« Proxy/FilterStack.pm ↑ Summary Proxy/Engine/NoFork.pm »
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
BranchTrueFalseTotal
if ($class eq "HTTP::Proxy::Engine") 78 4 82
20 78 my $engine = delete $params{engine};
21 $engine = $engines{$^O} || $engines{default}
22 78 ▶ unless defined $engine;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $engine 72 6 78
Condition33%1/3
$engines{$^O} || $engines{'default'}
l!l&&r!l&&!r
0720
MC/DC0%0/2
$engines{$^O} || $engines{'default'}
$engines{$^O} $engines{'default'}
Truth table33%1/3
A || B
A= $engines{$^O}B= $engines{'default'}
ABresult
1X1
011
000
23  
24 78 $class = "HTTP::Proxy::Engine::$engine";
25 78 eval "require $class";
26 78 ▶ croak $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 77 78
27 }
28  
29 # some error checking
30 croak "No proxy defined"
31 81 ▶ unless exists $params{proxy};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"proxy"} 3 78 81
32 croak "$params{proxy} is not a HTTP::Proxy object"
33 78 ▶ unless UNIVERSAL::isa( $params{proxy}, 'HTTP::Proxy' );
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($params{"proxy"}, "HTTP::Proxy") 2 76 78
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
BranchTrueFalseTotal
if defined $_[1] 72 440 512
60 512 $_[0]{$attr};
61 272 };
62 }
63 }
64  
65 67 1;
66  
67 __END__
« Proxy/FilterStack.pm ↑ Summary Proxy/Engine/NoFork.pm »