blib/lib/Mojolicious/Plugin/RemoteAddr.pm

filter: Statementstmt 94.7% 18 / 19 Branchbran 75.0% 9 / 12 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 3 / 3 Podpod 100% 1 / 1 totaltotal 84.2% 32 / 38 CC 9 SCAR 18.8
CC
9
Cov
85%
__ANON__
8.3
register
2.0
BEGIN
1.0
CRAP 6.5
↑ Summary
1 package Mojolicious::Plugin::RemoteAddr;
2 1 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 our $VERSION = '0.03';
5  
6 1 ▶sub register {
Subroutine register: called CC=2 SCAR=7.0
Pod documented
7 1 my ($self, $app, $conf) = @_;
8  
9 1 ▶ $conf->{order} ||= ['x-real-ip', 'x-forwarded-for', 'tx'];
Condition50%1/2
$conf->{"order"} ||= ["x-real-ip", "x-forwarded-for", "tx"]
l!l
01
MC/DC0%0/1
$conf->{"order"} ||= ["x-real-ip", "x-forwarded-for", "tx"]
$conf->{"order"}
Truth table50%1/2
A
A= $conf->{"order"}
Aresult
11
00
10  
11 2 ▶ $app->helper( remote_addr => sub {
Subroutine __ANON__: called CC=8 SCAR=21.2
12 2 my $c = shift;
13  
14 2 foreach my $place ( @{ $conf->{order} } ) {
15 4 ▶ if ( $place eq 'x-real-ip' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($place eq 'x-real-ip') { } 2 2 4
elsif ($place eq 'x-forwarded-for') { } 1 1 2
elsif ($place eq 'tx') { } 1 0 1
16 2 my $ip = $c->req->headers->header('X-Real-IP');
17 2 ▶ return $ip if $ip;
Branch: 1 branch
BranchTrueFalseTotal
if $ip 1 1 2
18 } elsif ( $place eq 'x-forwarded-for' ) {
19 1 my $ip = $c->req->headers->header('X-Forwarded-For');
20 1 ▶ return $ip if $ip;
Branch: 1 branch
BranchTrueFalseTotal
if $ip 0 1 1
21 } elsif ( $place eq 'tx' ) {
22 1 my $ip = $c->tx->remote_address;
23 1 ▶ return $ip if $ip;
Branch: 1 branch
BranchTrueFalseTotal
if $ip 1 0 1
24 }
25 }
26  
27 0 return;
28 1 });
29 }
30  
31 1 1;
32 __END__
↑ Summary