UserAgent/Base/IS.pm

filter: Statementstmt 13.4% 11 / 82 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 115 MC/DCmcdc 0.0% 0 / 57 Subroutinesub 15.0% 3 / 20 Podpod n/a totaltotal 4.7% 14 / 298 CC 52 SCAR 36.1
CC
52
Cov
5%
_is_netscape
72.0
_is_safari
56.0
_is_chrome
56.0
CRAP 36.8
« UserAgent/Base/Dumper.pm ↑ Summary UserAgent/Base/Accessors.pm »
1 package Parse::HTTP::UserAgent::Base::IS;
2 4 $Parse::HTTP::UserAgent::Base::IS::VERSION = '0.43';
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Parse::HTTP::UserAgent::Constants qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶sub _is_opera_pre {
Subroutine _is_opera_pre: not called CC=1 SCAR=6.9
8 0 my($self, $moz) = @_;
9 0 return index( $moz, 'Opera') != NO_IMATCH;
10 }
11  
12 0 ▶sub _is_opera_post {
Subroutine _is_opera_post: not called CC=2 SCAR=17.9
13 0 my($self, $extra) = @_;
14 0 ▶ return $extra && $extra->[0] eq 'Opera';
Condition0%0/3
$extra && $extra->[0] eq 'Opera'
!ll&&!rl&&r
000
MC/DC0%0/2
$extra && $extra->[0] eq 'Opera'
$extra $extra->[0] eq 'Opera'
Truth table0%0/3
A && B
A= $extraB= $extra->[0] eq 'Opera'
ABresult
0X0
100
111
15 }
16  
17 0 ▶sub _is_opera_ff { # opera faking as firefox
Subroutine _is_opera_ff: not called CC=3 SCAR=24.8
18 0 my($self, $extra) = @_;
19 return $extra
20 0 ▶ && @{$extra} == OPERA_FAKER_EXTRA_SIZE
Condition0%0/6
$extra && @{$extra;} == 4 && $extra->[2] eq 'Opera'
!ll&&!rl&&r
000
$extra and @{$extra;} == 4
!ll&&!rl&&r
000
MC/DC0%0/3
$extra && @{$extra;} == 4 && $extra->[2] eq 'Opera'
$extra @{$extra;} == 4 $extra->[2] eq 'Opera'
Truth table0%0/4
A and B && C
A= $extraB= @{$extra;} == 4C= $extra->[2] eq 'Opera'
ABCresult
0XX0
10X0
1100
1111
21 && $extra->[2] eq 'Opera';
22 }
23  
24 0 ▶sub _is_safari {
Subroutine _is_safari: not called CC=7 SCAR=40.3
25 0 my($self, $extra, $others) = @_;
26 0 my $str = $self->[UA_STRING];
27 # epiphany?
28 return index( $str , 'Chrome' ) != NO_IMATCH ? 0 # faker
29 : index( $str , 'Android' ) != NO_IMATCH ? 0 # faker
30 : $extra && index( $extra->[0] , 'AppleWebKit' ) != NO_IMATCH ? 1
31 0 ▶ : @{$others} && index( $others->[LAST_ELEMENT], 'Safari' ) != NO_IMATCH ? 1
Branch: 4 branches
BranchTrueFalseTotal
index($str, 'Chrome') != -1 ? : 0 0 0
index($str, 'Android') != -1 ? : 0 0 0
$extra && index($extra->[0], 'AppleWebKit') != -1 ? : 0 0 0
@{$others;} && index($others->[-1], 'Safari') != -1 ? : 0 0 0
Condition0%0/6
$extra and index($extra->[0], "AppleWebKit") != -1
!ll&&!rl&&r
000
@{$others;} and index($others->[-1], "Safari") != -1
!ll&&!rl&&r
000
MC/DC0%0/2
$extra and index($extra->[0], "AppleWebKit") != -1
$extra index($extra->[0], "AppleWebKit") != -1
MC/DC0%0/2
@{$others;} and index($others->[-1], "Safari") != -1
@{$others;} index($others->[-1], "Safari") != -1
Truth table0%0/3
A and B
A= $extraB= index($extra->[0], "AppleWebKit") != -1
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= @{$others;}B= index($others->[-1], "Safari") != -1
ABresult
0X0
100
111
32 : 0
33 ;
34 }
35  
36 0 ▶sub _is_chrome {
Subroutine _is_chrome: not called CC=7 SCAR=40.3
37 0 my($self, $extra, $others) = @_;
38 0 ▶ my $chx = $others->[1] || return;
Condition0%0/2
$others->[1] || (return)
l!l
00
MC/DC0%0/1
$others->[1] || (return)
$others->[1]
Truth table0%0/2
A
A= $others->[1]
Aresult
11
00
39 0 my($chrome, $safari) = split RE_WHITESPACE, $chx;
40 0 ▶ return if ! ( $chrome && $safari);
Branch: 1 branch
BranchTrueFalseTotal
unless $chrome and $safari 0 0 0
Condition0%0/3
$chrome and $safari
!ll&&!rl&&r
000
MC/DC0%0/2
$chrome and $safari
$chrome $safari
Truth table0%0/3
A and B
A= $chromeB= $safari
ABresult
0X0
100
111
41  
42 0 ▶ return index( $chrome , 'Chrome' ) != NO_IMATCH &&
Condition0%0/9
index($chrome, 'Chrome') != -1 && index($safari, 'Safari') != -1 && ($extra && index($extra->[0], 'AppleWebKit') != -1)
!ll&&!rl&&r
000
index($chrome, "Chrome") != -1 and index($safari, "Safari") != -1
!ll&&!rl&&r
000
$extra and index($extra->[0], "AppleWebKit") != -1
!ll&&!rl&&r
000
MC/DC0%0/4
index($chrome, 'Chrome') != -1 && index($safari, 'Safari') != -1 && ($extra && index($extra->[0], 'AppleWebKit') != -1)
index($chrome, "Chrome") != -1 index($safari, "Safari") != -1 $extra index($extra->[0], "AppleWebKit") != -1
Truth table0%0/5
A and B && C and D
A= index($chrome, "Chrome") != -1B= index($safari, "Safari") != -1C= $extraD= index($extra->[0], "AppleWebKit") != -1
ABCDresult
0XXX0
10XX0
110X0
11100
11111
43 index( $safari , 'Safari' ) != NO_IMATCH &&
44 ( $extra && index( $extra->[0], 'AppleWebKit') != NO_IMATCH);
45 }
46  
47 0 ▶sub _is_android {
Subroutine _is_android: not called CC=7 SCAR=40.3
48 0 my($self, $thing, $others) = @_;
49 0 my $has_android = grep { index( lc $_, 'android' ) != NO_IMATCH } @{ $thing };
50 0 my $has_safari = grep { index( lc $_, 'safari' ) != NO_IMATCH } @{ $others };
51 0 ▶ if ( $has_android && $has_safari ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_android and $has_safari) 0 0 0
Condition0%0/3
$has_android and $has_safari
!ll&&!rl&&r
000
MC/DC0%0/2
$has_android and $has_safari
$has_android $has_safari
Truth table0%0/3
A and B
A= $has_androidB= $has_safari
ABresult
0X0
100
111
52 0 return 1;
53 }
54 0 ▶ if ( @{ $others } == 0
Branch: 1 branch
BranchTrueFalseTotal
if (@{$others;} == 0 and @{$thing;} > 0 and $thing->[-1] and index($thing->[-1], "AppleWebKit") != -1) 0 0 0
Condition0%0/9
@{$others;} == 0 and @{$thing;} > 0 and $thing->[-1] and index($thing->[-1], "AppleWebKit") != -1
!ll&&!rl&&r
000
@{$others;} == 0 and @{$thing;} > 0 and $thing->[-1]
!ll&&!rl&&r
000
@{$others;} == 0 and @{$thing;} > 0
!ll&&!rl&&r
000
MC/DC0%0/4
@{$others;} == 0 and @{$thing;} > 0 and $thing->[-1] and index($thing->[-1], "AppleWebKit") != -1
@{$others;} == 0 @{$thing;} > 0 $thing->[-1] index($thing->[-1], "AppleWebKit") != -1
Truth table0%0/5
A and B and C and D
A= @{$others;} == 0B= @{$thing;} > 0C= $thing->[-1]D= index($thing->[-1], "AppleWebKit") != -1
ABCDresult
0XXX0
10XX0
110X0
11100
11111
55 0 && @{ $thing } > 0
56 && $thing->[-1]
57 && index( $thing->[-1], 'AppleWebKit' ) != NO_IMATCH
58 ) {
59 # More stupidity: ua string is missing a closing paren
60 0 my($part, @rest) = split m{(AppleWebKit)}xms, $thing->[-1];
61 0 $thing->[-1] = $part;
62 0 @{ $others } = map { $self->trim( $_ ) }
63 split m{ (\QKHTML, like Gecko\E) }xms,
64 join q{}, @rest;
65 0 return 1;
66 }
67 0 return;
68 }
69  
70 0 ▶sub _is_ff {
Subroutine _is_ff: not called CC=6 SCAR=37.4
71 0 my($self, $extra) = @_;
72 0 ▶ return if ! $extra || ! $extra->[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $extra and $extra->[1] 0 0 0
Condition0%0/3
$extra and $extra->[1]
!ll&&!rl&&r
000
MC/DC0%0/2
$extra and $extra->[1]
$extra $extra->[1]
Truth table0%0/3
A and B
A= $extraB= $extra->[1]
ABresult
0X0
100
111
73 0 ▶ my $moz_with_name = $extra->[1] eq 'Mozilla' && $extra->[2];
Condition0%0/3
$extra->[1] eq 'Mozilla' && $extra->[2]
!ll&&!rl&&r
000
MC/DC0%0/2
$extra->[1] eq 'Mozilla' && $extra->[2]
$extra->[1] eq 'Mozilla' $extra->[2]
Truth table0%0/3
A && B
A= $extra->[1] eq 'Mozilla'B= $extra->[2]
ABresult
0X0
100
111
74 return $moz_with_name
75 0 ▶ ? $extra->[2] =~ RE_FIREFOX_NAMES && do { $extra->[1] = $extra->[2] }
Branch: 1 branch
BranchTrueFalseTotal
$moz_with_name ? : 0 0 0
Condition0%0/3
$extra->[2] =~ / Firefox|Iceweasel|Firebird|Phoenix /msx and do { $extra->[1] = $extra->[2] }
!ll&&!rl&&r
000
MC/DC0%0/2
$extra->[2] =~ / Firefox|Iceweasel|Firebird|Phoenix /msx and do { $extra->[1] = $extra->[2] }
$extra->[2] =~ / Firefox|Iceweasel|Firebird|Phoenix /msx do { $extra->[1] = $extra->[2] }
Truth table0%0/3
A and B
A= $extra->[2] =~ / Firefox|Iceweasel|Firebird|Phoenix /msxB= do { $extra->[1] = $extra->[2] }
ABresult
0X0
100
111
76 : $extra->[1] =~ RE_FIREFOX_NAMES
77 ;
78 }
79  
80 0 ▶sub _is_suspicious_ff {
Subroutine _is_suspicious_ff: not called CC=4 SCAR=30.0
81 0 my($self, $extra) = @_;
82 return if ref $extra ne 'ARRAY'
83 0 ▶ || @{ $extra } != 1
Branch: 1 branch
BranchTrueFalseTotal
if ref $extra ne "ARRAY" or @{$extra;} != 1 or index(lc $extra->[0], "firefox/") == -1 0 0 0
Condition0%0/6
ref $extra ne "ARRAY" or @{$extra;} != 1 or index(lc $extra->[0], "firefox/") == -1
l!l&&r!l&&!r
000
ref $extra ne "ARRAY" or @{$extra;} != 1
l!l&&r!l&&!r
000
MC/DC0%0/3
ref $extra ne "ARRAY" or @{$extra;} != 1 or index(lc $extra->[0], "firefox/") == -1
ref $extra ne "ARRAY" @{$extra;} != 1 index(lc $extra->[0], "firefox/") == -1
Truth table0%0/4
A or B or C
A= ref $extra ne "ARRAY"B= @{$extra;} != 1C= index(lc $extra->[0], "firefox/") == -1
ABCresult
1XX1
01X1
0011
0000
84 || index( lc $extra->[0], 'firefox/' ) == NO_IMATCH;
85 0 return 1;
86 }
87  
88 0 ▶sub _is_gecko {
Subroutine _is_gecko: not called CC=1 SCAR=6.9
89 0 return index(shift->[UA_STRING], 'Gecko/') != NO_IMATCH;
90 }
91  
92 0 ▶sub _is_generic { #TODO: this is actually a parser
Subroutine _is_generic: not called CC=4 SCAR=30.0
93 0 my($self, @args) = @_;
94 0 ▶ return 1 if $self->_generic_name_version( @args ) ||
Branch: 1 branch
BranchTrueFalseTotal
if $self->_generic_name_version(@args) or $self->_generic_compatible(@args) or $self->_generic_moz_thing(@args) 0 0 0
Condition0%0/6
$self->_generic_name_version(@args) or $self->_generic_compatible(@args) or $self->_generic_moz_thing(@args)
l!l&&r!l&&!r
000
$self->_generic_name_version(@args) or $self->_generic_compatible(@args)
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->_generic_name_version(@args) or $self->_generic_compatible(@args) or $self->_generic_moz_thing(@args)
$self->_generic_name_version(@args) $self->_generic_compatible(@args) $self->_generic_moz_thing(@args)
Truth table0%0/4
A or B or C
A= $self->_generic_name_version(@args)B= $self->_generic_compatible(@args)C= $self->_generic_moz_thing(@args)
ABCresult
1XX1
01X1
0011
0000
95 $self->_generic_compatible( @args ) ||
96 $self->_generic_moz_thing( @args );
97 0 return;
98 }
99  
100 0 ▶sub _is_netscape {
Subroutine _is_netscape: not called CC=8 SCAR=42.8
101 0 my($self, $moz, $thing, $extra, $compatible, @others) = @_;
102  
103 my $rv = index($moz, 'Mozilla/') != NO_IMATCH &&
104 $moz ne 'Mozilla/4.0' &&
105 ! $compatible &&
106 ! $extra &&
107 ! @others &&
108 0 ▶ ( @{$thing} && $thing->[LAST_ELEMENT] ne 'Sun' ) && # hotjava
Condition0%0/21
index($moz, 'Mozilla/') != -1 && $moz ne 'Mozilla/4.0' && !$compatible && !$extra && !@others && (@{$thing;} && $thing->[-1] ne 'Sun') && index($thing->[0], 'http://') == -1
!ll&&!rl&&r
000
index($moz, "Mozilla/") != -1 and $moz ne "Mozilla/4.0" and not $compatible and not $extra and not @others and (@{$thing;} and $thing->[-1] ne "Sun")
!ll&&!rl&&r
000
index($moz, "Mozilla/") != -1 and $moz ne "Mozilla/4.0" and not $compatible and not $extra and not @others
!ll&&!rl&&r
000
index($moz, "Mozilla/") != -1 and $moz ne "Mozilla/4.0" and not $compatible and not $extra
!ll&&!rl&&r
000
index($moz, "Mozilla/") != -1 and $moz ne "Mozilla/4.0" and not $compatible
!ll&&!rl&&r
000
index($moz, "Mozilla/") != -1 and $moz ne "Mozilla/4.0"
!ll&&!rl&&r
000
@{$thing;} and $thing->[-1] ne "Sun"
!ll&&!rl&&r
000
MC/DC0%0/8
index($moz, 'Mozilla/') != -1 && $moz ne 'Mozilla/4.0' && !$compatible && !$extra && !@others && (@{$thing;} && $thing->[-1] ne 'Sun') && index($thing->[0], 'http://') == -1
index($moz, "Mozilla/") != -1 $moz ne "Mozilla/4.0" not $compatible not $extra not @others @{$thing;} $thing->[-1] ne "Sun" index($thing->[0], 'http://') == -1
Truth table0%0/9
A and B and not(C) and not(D) and not(E) and F and G && H
A= index($moz, "Mozilla/") != -1B= $moz ne "Mozilla/4.0"C= not $compatibleD= not $extraE= not @othersF= @{$thing;}G= $thing->[-1] ne "Sun"H= index($thing->[0], 'http://') == -1
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
111110XX0
1111110X0
111111100
111111111
109 index($thing->[0], 'http://') == NO_IMATCH # robot
110 ;
111 0 return $rv;
112 }
113  
114 0 ▶sub _is_docomo {
Subroutine _is_docomo: not called CC=1 SCAR=6.9
115 0 my($self, $moz) = @_;
116 0 return index(lc $moz, 'docomo') != NO_IMATCH;
117 }
118  
119 0 ▶sub _is_strength {
Subroutine _is_strength: not called CC=5 SCAR=34.0
120 0 my $self = shift;
121 0 ▶ my $s = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
122 0 $s = $self->trim( $s );
123 0 ▶ return $s if $s eq 'U' || $s eq 'I' || $s eq 'N';
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "U" or $s eq "I" or $s eq "N" 0 0 0
Condition0%0/6
$s eq "U" or $s eq "I" or $s eq "N"
l!l&&r!l&&!r
000
$s eq "U" or $s eq "I"
l!l&&r!l&&!r
000
MC/DC0%0/3
$s eq "U" or $s eq "I" or $s eq "N"
$s eq "U" $s eq "I" $s eq "N"
Truth table0%0/4
A or B or C
A= $s eq "U"B= $s eq "I"C= $s eq "N"
ABCresult
1XX1
01X1
0011
0000
124 0 return;
125 }
126  
127 0 ▶sub _is_emacs {
Subroutine _is_emacs: not called CC=1 SCAR=6.9
128 0 my($self, $moz) = @_;
129 0 return index( $moz, 'Emacs-W3/') != NO_IMATCH;
130 }
131  
132 0 ▶sub _is_moz_only {
Subroutine _is_moz_only: not called CC=4 SCAR=30.0
133 0 my($self, $moz, $thing, $extra, $compatible, @others) = @_;
134 0 ▶ return $moz && ! @{ $thing } && ! $extra && ! @others;
Condition0%0/9
$moz && !@{$thing;} && !$extra && !@others
!ll&&!rl&&r
000
$moz and not @{$thing;} and not $extra
!ll&&!rl&&r
000
$moz and not @{$thing;}
!ll&&!rl&&r
000
MC/DC0%0/4
$moz && !@{$thing;} && !$extra && !@others
$moz not @{$thing;} not $extra !@others
Truth table0%0/5
A and not(B) and not(C) && not(D)
A= $mozB= not @{$thing;}C= not $extraD= !@others
ABCDresult
0XXX0
10XX0
110X0
11100
11111
135 }
136  
137 0 ▶sub _is_hotjava {
Subroutine _is_hotjava: not called CC=2 SCAR=17.9
138 0 my($self, $moz, $thing, $extra, $compatible, @others) = @_;
139 0 my @hot = @{ $thing };
140 0 ▶ return @hot == 2 && $hot[1] eq 'Sun';
Condition0%0/3
@hot == 2 && $hot[1] eq 'Sun'
!ll&&!rl&&r
000
MC/DC0%0/2
@hot == 2 && $hot[1] eq 'Sun'
@hot == 2 $hot[1] eq 'Sun'
Truth table0%0/3
A && B
A= @hot == 2B= $hot[1] eq 'Sun'
ABresult
0X0
100
111
141 }
142  
143 0 ▶sub _is_generic_bogus_ie {
Subroutine _is_generic_bogus_ie: not called CC=5 SCAR=34.0
144 0 my($self, $extra) = @_;
145 0 ▶ my $rv = $extra
Condition0%0/12
$extra && $extra->[0] && index($extra->[0], 'compatible') != -1 && $extra->[1] && $extra->[1] eq 'MSIE'
!ll&&!rl&&r
000
$extra and $extra->[0] and index($extra->[0], "compatible") != -1 and $extra->[1]
!ll&&!rl&&r
000
$extra and $extra->[0] and index($extra->[0], "compatible") != -1
!ll&&!rl&&r
000
$extra and $extra->[0]
!ll&&!rl&&r
000
MC/DC0%0/5
$extra && $extra->[0] && index($extra->[0], 'compatible') != -1 && $extra->[1] && $extra->[1] eq 'MSIE'
$extra $extra->[0] index($extra->[0], "compatible") != -1 $extra->[1] $extra->[1] eq 'MSIE'
Truth table0%0/6
A and B and C and D && E
A= $extraB= $extra->[0]C= index($extra->[0], "compatible") != -1D= $extra->[1]E= $extra->[1] eq 'MSIE'
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
146 && $extra->[0]
147 && index( $extra->[0], 'compatible' ) != NO_IMATCH
148 && $extra->[1]
149 && $extra->[1] eq 'MSIE';
150 0 return $rv;
151 }
152  
153 4 1;
154  
155 __END__
« UserAgent/Base/Dumper.pm ↑ Summary UserAgent/Base/Accessors.pm »