UserAgent.pm

filter: Statementstmt 23.1% 48 / 207 Branchbran 3.9% 5 / 128 Conditioncond 2.9% 2 / 67 MC/DCmcdc 0.0% 0 / 39 Subroutinesub 57.1% 12 / 21 Podpod 100% 3 / 3 totaltotal 15.0% 70 / 465 CC 95 SCAR 59.2
CC
95
Cov
14%
_do_parse
1056.0
_extended_probe
210.0
_pre_parse
156.0
CRAP 371.5
↑ Summary UserAgent/Base/Parsers.pm »
1 package Parse::HTTP::UserAgent;
2 3 $Parse::HTTP::UserAgent::VERSION = '0.43';
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use parent qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
7 Parse::HTTP::UserAgent::Base::IS
8 Parse::HTTP::UserAgent::Base::Parsers
9 Parse::HTTP::UserAgent::Base::Dumper
10 Parse::HTTP::UserAgent::Base::Accessors
11 3 );
12  
13 3 ▶use overload '""', => 'name',
Subroutine BEGIN: called CC=1 SCAR=0.0
14 '0+', => 'version',
15 fallback => 1,
16 3 ;
17  
18 3 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use Parse::HTTP::UserAgent::Constants qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 3 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.6
23 3 ▶ constant->import( DEBUG => 0 ) if not defined &DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if not defined &Parse::HTTP::UserAgent::DEBUG 3 0 3
24 }
25  
26 3 my %OSFIX = (
27 'WinNT4.0' => 'Windows NT 4.0',
28 'WinNT' => 'Windows NT',
29 'Windows 4.0' => 'Windows 95',
30 'Win95' => 'Windows 95',
31 'Win98' => 'Windows 98',
32 'Windows 4.10' => 'Windows 98',
33 'Win 9x 4.90' => 'Windows Me',
34 'Windows NT 5.0' => 'Windows 2000',
35 'Windows NT 5.1' => 'Windows XP',
36 'Windows XP 5.1' => 'Windows XP', # huh?
37 'Windows NT 5.2' => 'Windows Server 2003',
38 'Windows NT 6.0' => 'Windows Vista / Server 2008',
39 'Windows NT 6.1' => 'Windows 7',
40 'Windows NT 6.2' => 'Windows 8',
41 'Windows NT 6.3' => 'Windows 8.1',
42 );
43  
44 282 ▶sub new {
Subroutine new: called CC=6 SCAR=18.5
Pod documented
45 282 my $class = shift;
46 282 ▶ my $ua = shift || croak 'No user agent string specified';
Condition50%1/2
shift() || croak('No user agent string specified')
l!l
2820
MC/DC0%0/1
shift() || croak('No user agent string specified')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
47 282 ▶ my $opt = shift || {};
Condition50%1/2
shift() || {}
l!l
0282
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
48 282 ▶ croak 'Options must be a hash reference' if ref $opt ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $opt ne "HASH" 0 282 282
49 282 my $self = [ map { undef } 0..MAXID ];
50 282 bless $self, $class;
51 282 @{ $self }[ UA_STRING, UA_STRING_ORIGINAL ] = ($ua) x 2;
52 282 ▶ $self->[IS_EXTENDED] = exists $opt->{extended} ? $opt->{extended} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{'extended'} ? : 0 282 282
53 282 ▶ $self->_normalize( $opt->{normalize} ) if $opt->{normalize};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"normalize"} 0 282 282
54 282 $self->_parse;
55 282 return $self;
56 }
57  
58 281 ▶sub as_hash {
Subroutine as_hash: called CC=2 SCAR=6.9
Pod documented
59 281 my $self = shift;
60 281 my %struct;
61 281 foreach my $id ( $self->_object_ids ) {
62 6463 (my $name = $id) =~ s{ \A UA_ }{}xms;
63 6463 $struct{ lc $name } = $self->[ $self->$id() ];
64 }
65 281 return %struct;
66 }
67  
68 0 ▶sub trim {
Subroutine trim: not called CC=2 SCAR=17.9
Pod documented
69 0 my $self = shift;
70 0 my $s = shift;
71 0 ▶ return $s if ! $s;
Branch: 1 branch
BranchTrueFalseTotal
unless $s 0 0 0
72 0 $s =~ s{ \A \s+ }{}xms;
73 0 $s =~ s{ \s+ \z }{}xms;
74 0 return $s;
75 }
76  
77 0 ▶sub _normalize {
Subroutine _normalize: not called CC=6 SCAR=37.4
78 0 my $self = shift;
79 0 my $nopt = shift;
80 0 my $type = ref $nopt;
81  
82 my @o = ! $type ? ':all'
83 0 ▶ : $type eq 'ARRAY' ? @{ $nopt }
Branch: 2 branches
BranchTrueFalseTotal
!$type ? : 0 0 0
$type eq 'ARRAY' ? : 0 0 0
84 : croak "Normalization option $nopt is invalid";
85  
86 0 my %mode = map { $_ => 1 } @o;
87 0 my @all = qw( plus_to_space trim_spaces );
88 0 ▶ @mode{ @all } = (1) x @all if delete $mode{':all'};
Branch: 1 branch
BranchTrueFalseTotal
if delete $mode{":all"} 0 0 0
89  
90 0 my $s = \$self->[UA_STRING];
91 0 ▶ ${$s} =~ s{[+]}{ }xmsg if $mode{plus_to_space};
Branch: 1 branch
BranchTrueFalseTotal
if $mode{"plus_to_space"} 0 0 0
92 0 ▶ ${$s} =~ s<\s+>< >xmsg if $mode{trim_spaces};
Branch: 1 branch
BranchTrueFalseTotal
if $mode{"trim_spaces"} 0 0 0
93 0 return;
94 }
95  
96 282 ▶sub _parse {
Subroutine _parse: called CC=3 SCAR=18.1
97 282 my $self = shift;
98 282 ▶ return $self if $self->[IS_PARSED];
Branch: 1 branch
BranchTrueFalseTotal
if $self->[26] 282 0 282
99 0 $self->_do_parse( $self->_pre_parse );
100 0 $self->[IS_PARSED] = 1;
101 0 ▶ $self->_post_parse if ! $self->[UA_UNKNOWN];
Branch: 1 branch
BranchTrueFalseTotal
unless $self->[26] 0 0 0
102 0 return;
103 }
104  
105 0 ▶sub _pre_parse {
Subroutine _pre_parse: not called CC=12 SCAR=50.5
106 0 my $self = shift;
107 0 my $ua = $self->[UA_STRING];
108 0 my $uc_ua = uc $ua;
109  
110 0 $self->[IS_MAXTHON] = index($uc_ua, 'MAXTHON') != NO_IMATCH;
111 0 $self->[IS_TRIDENT] = index($uc_ua, 'TRIDENT/') != NO_IMATCH;
112  
113 0 my @parts;
114 0 my $i = 0;
115 0 my $depth = 0;
116  
117 0 foreach my $token ( split RE_SPLIT_PARSE, $ua ) {
118 0 ▶ if ( $token eq '(' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq "(") 0 0 0
119 0 ▶ $i++ if ++$depth == 1;
Branch: 1 branch
BranchTrueFalseTotal
if ++$depth == 1 0 0 0
120 0 next;
121 }
122 0 ▶ if ( $token eq ')' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq ")") 0 0 0
123 0 ▶ $i++ if --$depth == 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$depth == 0 0 0 0
124 0 next;
125 }
126 0 ▶ push @{ $parts[$i] ||= [] }, $token;
Condition0%0/2
$parts[$i] ||= []
l!l
00
MC/DC0%0/1
$parts[$i] ||= []
$parts[$i]
Truth table0%0/2
A
A= $parts[$i]
Aresult
11
00
127 }
128  
129 # Hopefully the above code was successful and now we can set the actual
130 # tokens to use inside parsers.
131 0 ▶ my($moz) = join ' ', @{ shift(@parts) || [] };
Condition0%0/2
shift @parts || []
l!l
00
MC/DC0%0/1
shift @parts || []
shift @parts
Truth table0%0/2
A
A= shift @parts
Aresult
11
00
132 0 ▶ my($thing) = join ' ', @{ shift(@parts) || [] };
Condition0%0/2
shift @parts || []
l!l
00
MC/DC0%0/1
shift @parts || []
shift @parts
Truth table0%0/2
A
A= shift @parts
Aresult
11
00
133 0 ▶ my($extra) = join ' ', @{ shift(@parts) || [] };
Condition0%0/2
shift @parts || []
l!l
00
MC/DC0%0/1
shift @parts || []
shift @parts
Truth table0%0/2
A
A= shift @parts
Aresult
11
00
134 0 my(@others) = map { @{ $_ } } @parts;
135  
136 0 ▶ $thing = $thing ? [ split RE_SC_WS, $thing ] : [];
Branch: 1 branch
BranchTrueFalseTotal
$thing ? : 0 0 0
137 0 ▶ $extra = [ split RE_WHITESPACE, $extra ] if $extra;
Branch: 1 branch
BranchTrueFalseTotal
if $extra 0 0 0
138  
139 0 $self->_debug_pre_parse( $moz, $thing, $extra, @others ) if DEBUG;
140 0 return $moz, $thing, $extra, @others;
141 }
142  
143 0 ▶sub _do_parse {
Subroutine _do_parse: not called CC=32 SCAR=69.6
144 0 my($self, $m, $t, $e, @o) = @_;
145  
146 0 ▶ my $c = $t->[0] && $t->[0] eq 'compatible';
Condition0%0/3
$t->[0] && $t->[0] eq 'compatible'
!ll&&!rl&&r
000
MC/DC0%0/2
$t->[0] && $t->[0] eq 'compatible'
$t->[0] $t->[0] eq 'compatible'
Truth table0%0/3
A && B
A= $t->[0]B= $t->[0] eq 'compatible'
ABresult
0X0
100
111
147  
148 0 ▶ if ( $c
Branch: 1 branch
BranchTrueFalseTotal
if ($c and shift @{$t;} and !$e || $self->[26] and not $self->[26]) 0 0 0
Condition0%0/9
$c and shift @{$t;} and !$e || $self->[26] and not $self->[26]
!ll&&!rl&&r
000
$c and shift @{$t;} and !$e || $self->[26]
!ll&&!rl&&r
000
$c and shift @{$t;}
!ll&&!rl&&r
000
MC/DC0%0/4
$c and shift @{$t;} and !$e || $self->[26] and not $self->[26]
$c shift @{$t;} !$e || $self->[26] not $self->[26]
Truth table0%0/5
A and B and C and not(D)
A= $cB= shift @{$t;}C= !$e || $self->[26]D= not $self->[26]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
149 0 ▶ && shift @{$t} # just inline removal of "compatible"
Condition0%0/3
not $e or $self->[26]
l!l&&r!l&&!r
000
MC/DC0%0/2
not $e or $self->[26]
not $e $self->[26]
Truth table0%0/3
not(A) or B
A= not $eB= $self->[26]
ABresult
1X1
011
000
150 && ( ! $e || $self->[IS_TRIDENT] ) # older versions don't have junk outside, while newer might have
151 && ! $self->[IS_MAXTHON] # be sure that this is not the faker
152 ) {
153 0 my($n, $v) = split RE_WHITESPACE, $t->[0];
154 0 ▶ if ( $n eq 'MSIE' && index($m, q{ }) == NO_IMATCH ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq "MSIE" and index($m, " ") == -1) 0 0 0
Condition0%0/3
$n eq "MSIE" and index($m, " ") == -1
!ll&&!rl&&r
000
MC/DC0%0/2
$n eq "MSIE" and index($m, " ") == -1
$n eq "MSIE" index($m, " ") == -1
Truth table0%0/3
A and B
A= $n eq "MSIE"B= index($m, " ") == -1
ABresult
0X0
100
111
155 0 return $self->_parse_msie($m, $t, $e, $n, $v);
156 }
157 }
158  
159 0 ▶ if ( $self->[IS_TRIDENT] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[26]) 0 0 0
160 # http://blogs.msdn.com/b/ieinternals/archive/2013/09/21/internet-explorer-11-user-agent-string-ua-string-sniffing-compatibility-with-gecko-webkit.aspx
161 my %msie11 = map {
162 0 ▶ index( $_, 'Windows') != NO_IMATCH ? ( windows => 1 )
Branch: 3 branches
BranchTrueFalseTotal
index($_, 'Windows') != -1 ? : 0 0 0
index($_, 'Trident/') != -1 ? : 0 0 0
index($_, 'rv:') != -1 ? : 0 0 0
163 : index( $_, 'Trident/') != NO_IMATCH ? ( trident => 1 )
164 : index( $_, 'rv:') != NO_IMATCH ? ( version => 1 )
165 : ()
166 0 } @{ $t };
167 0 my $msie_matched = keys %msie11;
168  
169 0 ▶ if ( $msie_matched == 3 ){
Branch: 2 branches
BranchTrueFalseTotal
if ($msie_matched == 3) { } 0 0 0
elsif (not $self->[26] and $msie_matched == 2 and not $msie11{'version'}) { } 0 0 0
170 0 return $self->_parse_msie_11($m, $t, $e);
171 }
172 ▶ elsif ( ! $self->[IS_MAXTHON] && $msie_matched == 2 && ! $msie11{version} ) {
Condition0%0/6
not $self->[26] and $msie_matched == 2 and not $msie11{"version"}
!ll&&!rl&&r
000
not $self->[26] and $msie_matched == 2
!ll&&!rl&&r
000
MC/DC0%0/3
not $self->[26] and $msie_matched == 2 and not $msie11{"version"}
not $self->[26] $msie_matched == 2 not $msie11{"version"}
Truth table0%0/4
not(A) and B and not(C)
A= not $self->[26]B= $msie_matched == 2C= not $msie11{"version"}
ABCresult
0XX0
10X0
1100
1111
173 # another weird case. robot?
174 0 my(@buf, $vstr);
175 0 for my $junk ( @{ $t } ) {
176 0 ▶ if ( index( $junk, 'MSIE') != NO_IMATCH ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($junk, "MSIE") != -1) 0 0 0
177 0 $vstr = $junk;
178 0 next;
179 }
180 0 push @buf, $junk;
181 }
182  
183 0 my $rv = $self->_parse_msie($m, \@buf, $e, split( RE_WHITESPACE, $vstr ) );
184 0 return $rv;
185 }
186 # fall back to the dispatch table below
187 }
188  
189 0 ▶ my $rv = $self->[IS_MAXTHON] ? [ maxthon => $m, $t, $e, @o ]
Branch: 9 branches
BranchTrueFalseTotal
$self->[26] ? : 0 0 0
$self->_is_opera_pre($m) ? : 0 0 0
$self->_is_opera_post($e) ? : 0 0 0
$self->_is_opera_ff($e) ? : 0 0 0
$self->_is_ff($e) ? : 0 0 0
$self->_is_safari($e, \@o) ? : 0 0 0
$self->_is_chrome($e, \@o) ? : 0 0 0
$self->_is_android($t, \@o) ? : 0 0 0
$self->_is_suspicious_ff($e) ? : 0 0 0
190 : $self->_is_opera_pre($m) ? [ opera_pre => $m, $t, $e ]
191 : $self->_is_opera_post($e) ? [ opera_post => $m, $t, $e, $c ]
192 : $self->_is_opera_ff($e) ? [ opera_pre => "$e->[2]/$e->[3]", $t ]
193 : $self->_is_ff($e) ? [ firefox => $m, $t, $e, @o ]
194 : $self->_is_safari($e, \@o) ? [ safari => $m, $t, $e, @o ]
195 : $self->_is_chrome($e, \@o) ? [ chrome => $m, $t, $e, @o ]
196 : $self->_is_android($t,\@o) ? [ android => $m, $t, $e, @o ]
197 : $self->_is_suspicious_ff($e) ? [ ff_suspect => $m, $t, $e, @o ]
198 : undef;
199  
200 0 ▶ if ( $rv ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv) 0 0 0
201 0 my $pname = shift @{ $rv };
202 0 my $method = '_parse_' . $pname;
203 0 my $rvx = $self->$method( @{ $rv } );
204 0 ▶ if ( $rvx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rvx) 0 0 0
205 0 ▶ $self->[UA_PARSER] ||= $pname;
Condition0%0/3
$self->[26] ||= $pname
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[26] ||= $pname
$self->[26] $pname
Truth table0%0/3
A ||= B
A= $self->[26]B= $pname
ABresult
1X1
011
000
206 0 return $rvx;
207 }
208 }
209  
210 0 ▶ return $self->_extended_probe($m, $t, $e, $c, @o) if $self->[IS_EXTENDED];
Branch: 1 branch
BranchTrueFalseTotal
if $self->[26] 0 0 0
211  
212 0 $self->[UA_UNKNOWN] = 1; # give up
213 0 return;
214 }
215  
216 0 ▶sub _post_parse {
Subroutine _post_parse: not called CC=12 SCAR=50.5
217 0 my $self = shift;
218 0 ▶ $self->[UA_VERSION] = $self->_numify( $self->[UA_VERSION_RAW] )
Branch: 1 branch
BranchTrueFalseTotal
if $self->[26] 0 0 0
219 if $self->[UA_VERSION_RAW];
220  
221 0 my @buf;
222 0 foreach my $e ( @{ $self->[UA_EXTRAS] } ) {
223 0 ▶ if ( $self->_is_strength( $e ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_strength($e)) 0 0 0
224 0 $self->[UA_STRENGTH] = $e ;
225 0 next;
226 }
227 0 push @buf, $e;
228 }
229  
230 0 ▶ $self->[UA_EXTRAS] = @buf ? [ @buf ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@buf ? : 0 0 0
231  
232 0 ▶ if ( $self->[UA_TOOLKIT] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[26]) 0 0 0
233 0 my $v = $self->[UA_TOOLKIT][TK_ORIGINAL_VERSION];
234 0 ▶ push @{ $self->[UA_TOOLKIT] }, defined $v ? $self->_numify( $v ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 0 0 0
235 }
236  
237 0 ▶ if( $self->[UA_MOZILLA] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[26]) 0 0 0
238 0 $self->[UA_MOZILLA] =~ tr/a-z://d;
239 0 $self->[UA_MOZILLA] = [ $self->[UA_MOZILLA],
240 $self->_numify( $self->[UA_MOZILLA] ) ];
241 }
242  
243 0 ▶ if ( $self->[UA_OS] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[26]) 0 0 0
244 0 ▶ $self->[UA_OS] = $OSFIX{ $self->[UA_OS] } || $self->[UA_OS];
Condition0%0/3
$OSFIX{$self->[26]} || $self->[26]
l!l&&r!l&&!r
000
MC/DC0%0/2
$OSFIX{$self->[26]} || $self->[26]
$OSFIX{$self->[26]} $self->[26]
Truth table0%0/3
A || B
A= $OSFIX{$self->[26]}B= $self->[26]
ABresult
1X1
011
000
245 }
246  
247 0 foreach my $robo ( LIST_ROBOTS ) { # regex???
248 0 ▶ next if lc $robo ne lc $self->[UA_NAME];
Branch: 1 branch
BranchTrueFalseTotal
if lc $robo ne lc $self->[26] 0 0 0
249 0 $self->[UA_ROBOT] = 1;
250 0 last;
251 }
252 0 return;
253 }
254  
255 0 ▶sub _extended_probe {
Subroutine _extended_probe: not called CC=14 SCAR=53.5
256 0 my($self, @args) = @_;
257  
258 0 ▶ return if $self->_is_gecko && $self->_parse_gecko( @args );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_gecko and $self->_parse_gecko(@args) 0 0 0
Condition0%0/3
$self->_is_gecko and $self->_parse_gecko(@args)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_gecko and $self->_parse_gecko(@args)
$self->_is_gecko $self->_parse_gecko(@args)
Truth table0%0/3
A and B
A= $self->_is_geckoB= $self->_parse_gecko(@args)
ABresult
0X0
100
111
259 0 ▶ return if $self->_is_netscape( @args ) && $self->_parse_netscape( @args );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_netscape(@args) and $self->_parse_netscape(@args) 0 0 0
Condition0%0/3
$self->_is_netscape(@args) and $self->_parse_netscape(@args)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_netscape(@args) and $self->_parse_netscape(@args)
$self->_is_netscape(@args) $self->_parse_netscape(@args)
Truth table0%0/3
A and B
A= $self->_is_netscape(@args)B= $self->_parse_netscape(@args)
ABresult
0X0
100
111
260 0 ▶ return if $self->_is_docomo( @args ) && $self->_parse_docomo( @args );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_docomo(@args) and $self->_parse_docomo(@args) 0 0 0
Condition0%0/3
$self->_is_docomo(@args) and $self->_parse_docomo(@args)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_docomo(@args) and $self->_parse_docomo(@args)
$self->_is_docomo(@args) $self->_parse_docomo(@args)
Truth table0%0/3
A and B
A= $self->_is_docomo(@args)B= $self->_parse_docomo(@args)
ABresult
0X0
100
111
261 0 ▶ return if $self->_is_generic( @args );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_generic(@args) 0 0 0
262 0 ▶ return if $self->_is_emacs( @args ) && $self->_parse_emacs( @args );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_emacs(@args) and $self->_parse_emacs(@args) 0 0 0
Condition0%0/3
$self->_is_emacs(@args) and $self->_parse_emacs(@args)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_emacs(@args) and $self->_parse_emacs(@args)
$self->_is_emacs(@args) $self->_parse_emacs(@args)
Truth table0%0/3
A and B
A= $self->_is_emacs(@args)B= $self->_parse_emacs(@args)
ABresult
0X0
100
111
263 0 ▶ return if $self->_is_moz_only( @args ) && $self->_parse_moz_only( @args );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_moz_only(@args) and $self->_parse_moz_only(@args) 0 0 0
Condition0%0/3
$self->_is_moz_only(@args) and $self->_parse_moz_only(@args)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_moz_only(@args) and $self->_parse_moz_only(@args)
$self->_is_moz_only(@args) $self->_parse_moz_only(@args)
Truth table0%0/3
A and B
A= $self->_is_moz_only(@args)B= $self->_parse_moz_only(@args)
ABresult
0X0
100
111
264 0 ▶ return if $self->_is_hotjava( @args ) && $self->_parse_hotjava( @args );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_hotjava(@args) and $self->_parse_hotjava(@args) 0 0 0
Condition0%0/3
$self->_is_hotjava(@args) and $self->_parse_hotjava(@args)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_hotjava(@args) and $self->_parse_hotjava(@args)
$self->_is_hotjava(@args) $self->_parse_hotjava(@args)
Truth table0%0/3
A and B
A= $self->_is_hotjava(@args)B= $self->_parse_hotjava(@args)
ABresult
0X0
100
111
265  
266 0 $self->[UA_UNKNOWN] = 1;
267 0 return;
268 }
269  
270 281 ▶sub _object_ids {
Subroutine _object_ids: called CC=1 SCAR=0.0
271 281 return grep { $_ =~ RE_OBJECT_ID } keys %Parse::HTTP::UserAgent::;
272 }
273  
274 0 ▶sub _numify {
Subroutine _numify: not called CC=12 SCAR=50.5
275 0 my $self = shift;
276 0 ▶ my $v = shift || return 0;
Condition0%0/2
shift() || (return 0)
l!l
00
MC/DC0%0/1
shift() || (return 0)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
277 0 my @removed;
278  
279 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ s/( pre | rel | alpha | beta | \-stable | gold | [ab]\d+ | a\-XXXX | dev | [+] )//gimsx) 0 0 0
280 $v =~ s{(
281 pre |
282 rel |
283 alpha |
284 beta |
285 \-stable |
286 gold |
287 [ab]\d+ |
288 a\-XXXX |
289 dev |
290 [+]
291 )}{}xmsig
292 ){
293 0 push @removed, $1 if INSIDE_VERBOSE_TEST;
294 }
295  
296 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ s/( (?:[^0-9]+)? # usually dash rc # nonsense [\-_.]? # usually dash ([0-9]) # teh candidate revision )/.0.$2/imsx) 0 0 0
297 $v =~ s{(
298 (?:[^0-9]+)? # usually dash
299 rc # nonsense
300 [\-_.]? # usually dash
301 ([0-9]) # teh candidate revision
302 )}{.0.$2}xmsi # yeah, hacky
303 ) {
304 0 push @removed, $1 if INSIDE_VERBOSE_TEST;
305 }
306  
307 # workaround another stupidity (1.2.3-4)
308 0 ▶ if ( my $rc = $v =~ tr/-/./ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rc = $v =~ tr/\-/./) 0 0 0
309 0 push @removed, '-' x $rc if INSIDE_VERBOSE_TEST;
310 }
311  
312 # convert _ to .
313 # version.pm has changed its interpretation of versions with underlines
314 # cf. https://bugs.debian.org/825611
315 0 ▶ if ( my $rc = $v =~ tr/_/./ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rc = $v =~ tr/_/./) 0 0 0
316 0 push @removed, '-' x $rc if INSIDE_VERBOSE_TEST;
317 }
318  
319 # Finally, be aggressive to prevent dying on bogus stuff.
320 # It's interesting how people provide highly stupid version "numbers".
321 # Version parameters are probably more stupid than the UA string itself.
322 0 ▶ if ( $v =~ s<([^0-9._v])><.>xmsg ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ s/([^0-9._v])/./gmsx) 0 0 0
323 0 push @removed, $1 if INSIDE_VERBOSE_TEST;
324 }
325  
326 0 ▶ if ( $v =~ s<([.]{2,})><.>xmsg ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ s/([.]{2,})/./gmsx) 0 0 0
327 0 push @removed, $1 if INSIDE_VERBOSE_TEST;
328 }
329  
330 0 if ( INSIDE_VERBOSE_TEST ) {
331 if ( @removed ) {
332 my $r = join q{','}, @removed;
333 require Test::More;
334 Test::More::diag("[DEBUG] _numify: removed '$r' from version string");
335 }
336 }
337  
338 # Gecko revisions like: "20080915000512" will cause an
339 # integer overflow warning. use bigint?
340 0 ▶ local $SIG{__WARN__} = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
341 0 my $msg = shift;
342 0 ▶ warn "$msg\n" if $msg !~ RE_WARN_OVERFLOW && $msg !~ RE_WARN_INVALID;
Branch: 1 branch
BranchTrueFalseTotal
if not $msg =~ / Integer\ overflow\ in\ version /msx || $msg =~ / Version\ string .+? contains\ invalid\ data\;\ ignoring\:/msx 0 0 0
Condition0%0/3
$msg =~ / Integer\ overflow\ in\ version /msx || $msg =~ / Version\ string .+? contains\ invalid\ data\;\ ignoring\:/msx
l!l&&r!l&&!r
000
MC/DC0%0/2
$msg =~ / Integer\ overflow\ in\ version /msx || $msg =~ / Version\ string .+? contains\ invalid\ data\;\ ignoring\:/msx
$msg =~ / Integer\ overflow\ in\ version /msx $msg =~ / Version\ string .+? contains\ invalid\ data\;\ ignoring\:/msx
Truth table0%0/3
A || B
A= $msg =~ / Integer\ overflow\ in\ version /msxB= $msg =~ / Version\ string .+? contains\ invalid\ data\;\ ignoring\:/msx
ABresult
1X1
011
000
343 0 };
344 # if version::vpp is used it'll identify 420 as a v-string
345 # add a floating point to fool it
346 0 ▶ $v .= q{.0} if index($v, q{.}) == NO_IMATCH;
Branch: 1 branch
BranchTrueFalseTotal
if index($v, ".") == -1 0 0 0
347 0 (my $check = $v) =~ tr/0-9//cd;
348 0 ▶ return 0 if ! $check; # A string parsed as version (i.e.: AppleWebKit/en_SG)
Branch: 1 branch
BranchTrueFalseTotal
unless $check 0 0 0
349 0 my $rv;
350 eval {
351 0 $rv = version->new("$v")->numify;
352 0 1;
353 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $rv = "version"->new("$v")->numify; 1 } } or do { my $error = $@ || "[unknown error while parsing version]"; do { croak($error) } } 0 0 0
354 0 ▶ my $error = $@ || '[unknown error while parsing version]';
Condition0%0/2
$@ || '[unknown error while parsing version]'
l!l
00
MC/DC0%0/1
$@ || '[unknown error while parsing version]'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
355 0 if ( INSIDE_UNIT_TEST ) {
356 chomp $error;
357 if ( INSIDE_VERBOSE_TEST ) {
358 Test::More::diag( "[FATAL] _numify: version said: $error for '$v'" );
359 Test::More::diag(
360 sprintf '[FATAL] _numify: UA with bogus version (%s) is: %s',
361 $v, $self->[UA_STRING]
362 );
363 Test::More::diag( '[FATAL] _numify: ' . $self->dumper );
364 }
365 croak $error;
366 }
367 else {
368 0 croak $error;
369 }
370 };
371 0 return $rv;
372 }
373  
374 0 ▶sub _debug_pre_parse {
Subroutine _debug_pre_parse: not called CC=1 SCAR=6.9
375 0 my($self, $moz, $thing, $extra, @others) = @_;
376  
377 0 my $raw = [
378 { qw/ name moz value / => $moz },
379 { qw/ name thing value / => $thing },
380 { qw/ name extra value / => $extra },
381 { qw/ name others value / => \@others },
382 ];
383 0 my $pok = print "-------------- PRE PARSE DUMP --------------\n"
384 . $self->dumper(args => $raw)
385 . "--------------------------------------------\n";
386 0 return;
387 }
388  
389 3 1;
390  
391 __END__
↑ Summary UserAgent/Base/Parsers.pm »