blib/lib/CGI/BrowserDetect.pm

filter: Statementstmt 100% 35 / 35 Branchbran 100% 14 / 14 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 11 / 11 Podpod 100% 7 / 7 totaltotal 100% 77 / 77 CC 10 SCAR 8.8
CC
10
Cov
100%
new
4.0
detect
3.0
device_type
3.0
CRAP 2.4
↑ Summary
1 package CGI::BrowserDetect;
2 2 ▶use 5.006; use strict; use warnings; our $VERSION = '1.02';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use base qw/HTTP::BrowserDetect/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
6 4 my $pkg = shift;
7 4 my $count = scalar @_;
8  
9 4 ▶ my %args = $count == 2
Branch: 2 branches
BranchTrueFalseTotal
$count == 2 ? : 1 3 4
$count == 1 ? : 2 1 3
10 ? (HTTP_USER_AGENT => shift, HTTP_ACCEPT_LANGUAGE => shift)
11 : $count == 1
12 ? (HTTP_USER_AGENT => shift)
13 : @_;
14  
15 4 my $self = $pkg->SUPER::new($args{HTTP_USER_AGENT});
16  
17 4 ▶ if ($args{HTTP_ACCEPT_LANGUAGE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"HTTP_ACCEPT_LANGUAGE"}) 2 2 4
18 2 $self->{accept_language} = $args{HTTP_ACCEPT_LANGUAGE};
19 2 ($self->{_lang}, $self->{_cnty}) = $self->{accept_language} =~ /([a-z]{2})\-([A-Z]{2})/;
20 }
21  
22 4 return $self;
23 }
24  
25 4 ▶sub detect {
Subroutine detect: called CC=3 SCAR=11.0
Pod documented
26 4 my ($self, @want) = @_;
27 my %provide = map {
28 4 ▶ $self->$_ ? ( $_ => $self->$_ ) : ()
Branch: 1 branch
BranchTrueFalseTotal
$self->$_ ? : 21 3 24
29 } @want;
30 4 ▶ return wantarray ? %provide : \%provide;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 3 4
31 }
32  
33 8 ▶sub device_type {
Subroutine device_type: called CC=3 SCAR=11.0
Pod documented
34 8 my ($self) = @_;
35  
36 8 ▶ return $self->mobile
Branch: 2 branches
BranchTrueFalseTotal
$self->mobile ? : 2 6 8
$self->tablet ? : 4 2 6
37 ? 'mobile'
38 : $self->tablet
39 ? 'tablet'
40 : 'computer';
41 }
42  
43 4 ▶sub lang { language(@_); } # backward comp
Subroutine lang: called CC=1 SCAR=0.0
Pod documented
44  
45 11 ▶sub language {
Subroutine language: called CC=2 SCAR=6.9
Pod documented
46 11 my ($self) = @_;
47 11 my $language = $self->SUPER::language();
48 11 ▶ return $language || $self->{_lang};
Condition100%3/3
$language || $self->{'_lang'}
l!l&&r!l&&!r
281
MC/DC100%2/2
$language || $self->{'_lang'}
$language $self->{'_lang'}
Truth table100%3/3
A || B
A= $languageB= $self->{'_lang'}
ABresult
1X1
011
000
49 }
50  
51 4 ▶sub cnty { country(@_); } # backwards
Subroutine cnty: called CC=1 SCAR=0.0
Pod documented
52  
53 11 ▶sub country {
Subroutine country: called CC=2 SCAR=6.9
Pod documented
54 11 my ($self) = @_;
55 11 my $country = $self->SUPER::country();
56 11 ▶ return $country || $self->{_cnty};
Condition100%3/3
$country || $self->{'_cnty'}
l!l&&r!l&&!r
281
MC/DC100%2/2
$country || $self->{'_cnty'}
$country $self->{'_cnty'}
Truth table100%3/3
A || B
A= $countryB= $self->{'_cnty'}
ABresult
1X1
011
000
57 }
58  
59 2 1;
60  
61 __END__
↑ Summary