MobileAgent/Base.pm

filter: Statementstmt 100% 35 / 35 Branchbran 75.0% 6 / 8 Conditioncond 77.7% 7 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 91.1% 62 / 68 CC 10 SCAR 13.8
CC
10
Cov
92%
env
7.1
_normalize_headers
3.0
list
2.0
CRAP 4.0
« MobileAgent/Softbank.pm ↑ Summary MobileAgent/Ezweb.pm »
1 package Test::MobileAgent::Base;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 352 ▶sub _modify_headers { shift; return @_ }
Subroutine _modify_headers: called CC=1 SCAR=0.0
8  
9 2106 ▶sub env {
Subroutine env: called CC=7 SCAR=19.6
Pod documented
10 2106 my ($class, $type, %extra_headers) = @_;
11  
12 2106 my $ua;
13 2106 ▶ if ($type and index($type, '/') >= $[) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type and index($type, '/') >= $[) { } 2094 12 2106
Condition100%3/3
$type and index($type, "/") >= $[
!ll&&!rl&&r
842094
MC/DC100%2/2
$type and index($type, "/") >= $[
$type index($type, "/") >= $[
Truth table100%3/3
A and B
A= $typeB= index($type, "/") >= $[
ABresult
0X0
100
111
14 # it looks like a full user agent.
15 2094 $ua = $type;
16 }
17 else {
18 # looking for a candidate from the list
19 12 my @list = $class->list;
20 12 ▶ $type = qr/\Q$type/ unless ref $type eq 'Regexp';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $type eq "Regexp" 12 0 12
21  
22 12 ▶ $ua = first { /$type/i } @list;
Subroutine __ANON__: called CC=1 SCAR=0.0
23  
24 12 ▶ $ua ||= $list[-1];
Condition33%1/3
$ua ||= $list[-1]
l!l&&r!l&&!r
1200
MC/DC0%0/2
$ua ||= $list[-1]
$ua $list[-1]
Truth table33%1/3
A ||= B
A= $uaB= $list[-1]
ABresult
1X1
011
000
25 }
26  
27 2106 my %headers = $class->_modify_headers(
28 HTTP_USER_AGENT => $ua,
29 _normalize_headers(%extra_headers),
30 );
31  
32 # remove private headers
33 2106 foreach my $header (keys %headers) {
34 3040 ▶ delete $headers{$header} if substr($header, 0, 1) eq '_';
Branch: 1 branch
BranchTrueFalseTotal
if substr($header, 0, 1) eq "_" 4 3036 3040
35 }
36 2106 return %headers;
37 }
38  
39 2106 ▶sub _normalize_headers {
Subroutine _normalize_headers: called CC=3 SCAR=11.0
40 2106 my %headers = @_;
41  
42 2106 my %new_headers;
43 2106 foreach my $header (keys %headers) {
44 32 my $new_header = uc $header;
45 32 $new_header =~ tr/-/_/;
46 32 ▶ $new_header = "HTTP_$new_header" if $new_header =~ /^X_/;
Branch: 1 branch
BranchTrueFalseTotal
if $new_header =~ /^X_/ 0 32 32
47 32 $new_headers{$new_header} = $headers{$header};
48 }
49 2106 return %new_headers;
50 }
51  
52 26 ▶sub list { grep { $_ and !/^#/ } split /\n/, (shift->_list) }
Subroutine list: called CC=2 SCAR=6.9
Pod documented
Condition100%3/3
$_ && !/^#/
!ll&&!rl&&r
26284470
MC/DC100%2/2
$_ && !/^#/
$_ !/^#/
Truth table100%3/3
A && not(B)
A= $_B= !/^#/
ABresult
0X0
100
111
53  
54 8 1;
55  
56 __END__
« MobileAgent/Softbank.pm ↑ Summary MobileAgent/Ezweb.pm »