MobileAgent/DoCoMo.pm

filter: Statementstmt 96.8% 93 / 96 Branchbran 85.7% 36 / 42 Conditioncond 77.7% 7 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 17 / 17 Podpod 77.7% 7 / 9 totaltotal 91.0% 163 / 179 CC 27 SCAR 17.3
CC
27
Cov
93%
_parse_foma
10.9
_parse_main
9.0
parse
4.0
CRAP 5.6
↑ Summary MobileAgent/DoCoMoDisplayMap.pm »
1 package HTTP::MobileAgent::DoCoMo;
2  
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 $VERSION = 0.19;
6  
7 9 ▶use base qw(HTTP::MobileAgent);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 9 __PACKAGE__->make_accessors(
10 qw(version model status bandwidth
11 serial_number is_foma card_id comment)
12 );
13  
14 9 ▶use HTTP::MobileAgent::DoCoMoDisplayMap qw($DisplayMap);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # various preferences
17 9 ▶use vars qw($DefaultCacheSize $HTMLVerMap $GPSModels);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 9 $DefaultCacheSize = 5;
19  
20 # http://www.nttdocomo.co.jp/p_s/imode/spec/useragent.html
21 9 $HTMLVerMap = [
22 # regex => version
23 qr/[DFNP]501i/ => '1.0',
24 qr/502i|821i|209i|691i|(F|N|P|KO)210i|^F671i$/ => '2.0',
25 qr/(D210i|SO210i)|503i|211i|SH251i|692i|200[12]|2101V/ => '3.0',
26 qr/504i|251i|^F671iS$|^F661i$|^F672i$|212i|SO213i|2051|2102V|2701/ => '4.0',
27 qr/eggy|P751v/ => '3.2',
28 qr/505i|506i|252i|253i|P213i|900i|901i|700i|880i/ => '5.0',
29 ];
30  
31 9 $GPSModels = { map { $_ => 1 } qw(F661i F505iGPS) };
32  
33 170 ▶sub is_docomo { 1 }
Subroutine is_docomo: called CC=1 SCAR=0.0
Pod documented
34  
35 32 ▶sub carrier { 'I' }
Subroutine carrier: called CC=1 SCAR=0.0
Pod documented
36  
37 32 ▶sub carrier_longname { 'DoCoMo' }
Subroutine carrier_longname: called CC=1 SCAR=0.0
Pod documented
38  
39 sub parse {
40 174 ▶ my $self = shift;
Subroutine parse: called CC=4 SCAR=13.9
Pod undocumented
41 174 my($main, $foma_or_comment) = split / /, $self->user_agent, 2;
42  
43 174 ▶ if ($foma_or_comment && $foma_or_comment =~ s/^\((.*)\)$/$1/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($foma_or_comment and $foma_or_comment =~ s/^\((.*)\)$/$1/) { } 4 170 174
elsif ($foma_or_comment) { } 17 153 170
Condition100%3/3
$foma_or_comment and $foma_or_comment =~ s/^\((.*)\)$/$1/
!ll&&!rl&&r
153174
MC/DC100%2/2
$foma_or_comment and $foma_or_comment =~ s/^\((.*)\)$/$1/
$foma_or_comment $foma_or_comment =~ s/^\((.*)\)$/$1/
Truth table100%3/3
A and B
A= $foma_or_commentB= $foma_or_comment =~ s/^\((.*)\)$/$1/
ABresult
0X0
100
111
44 # DoCoMo/1.0/P209is (Google CHTML Proxy/1.0)
45 4 $self->{comment} = $1;
46 4 $self->_parse_main($main);
47 } elsif ($foma_or_comment) {
48 # DoCoMo/2.0 N2001(c10;ser0123456789abcde;icc01234567890123456789)
49 17 $self->{is_foma} = 1;
50 17 @{$self}{qw(name version)} = split m!/!, $main;
51 17 $self->_parse_foma($foma_or_comment);
52 } else {
53 # DoCoMo/1.0/R692i/c10
54 153 $self->_parse_main($main);
55 }
56 }
57  
58 sub _parse_main {
59 157 ▶ my($self, $main) = @_;
Subroutine _parse_main: called CC=9 SCAR=22.0
60 157 my($name, $version, $model, $cache, @rest) = split m!/!, $main;
61 157 $self->{name} = $name;
62 157 $self->{version} = $version;
63 157 $self->{model} = $model;
64 157 ▶ $self->{model} = 'SH505i' if $self->{model} eq 'SH505i2';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"model"} eq "SH505i2" 1 156 157
65  
66 157 ▶ if ($cache) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache) 105 52 157
67 105 ▶ $cache =~ s/^c// or return $self->no_match;
Branch: 1 branch
BranchTrueFalseTotal
$cache =~ s/^c// or return $self->no_match 0 105 105
68 105 $self->{cache_size} = $cache;
69 }
70  
71 157 for (@rest) {
72 38 ▶ /^ser(\w{11})$/ and do { $self->{serial_number} = $1; next };
Branch: 1 branch
BranchTrueFalseTotal
/^ser(\w{11})$/ and do { $self->{"serial_number"} = $1; next } 5 33 38
73 33 ▶ /^(T[CDBJ])$/ and do { $self->{status} = $1; next };
Branch: 1 branch
BranchTrueFalseTotal
/^(T[CDBJ])$/ and do { $self->{"status"} = $1; next } 19 14 33
74 14 ▶ /^s(\d+)$/ and do { $self->{bandwidth} = $1; next };
Branch: 1 branch
BranchTrueFalseTotal
/^s(\d+)$/ and do { $self->{"bandwidth"} = $1; next } 5 9 14
75 9 ▶ /^W(\d+)H(\d+)$/ and do { $self->{display_bytes} = "$1*$2"; next; };
Branch: 1 branch
BranchTrueFalseTotal
/^W(\d+)H(\d+)$/ and do { $self->{"display_bytes"} = "$1*$2"; next } 3 6 9
76 }
77 }
78  
79 sub _parse_foma {
80 17 ▶ my($self, $foma) = @_;
Subroutine _parse_foma: called CC=10 SCAR=23.9
81  
82 17 ▶ $foma =~ s/^([^\(]+)// or return $self->no_match;
Branch: 1 branch
BranchTrueFalseTotal
$foma =~ s/^([^\(]+)// or return $self->no_match 0 17 17
83 17 $self->{model} = $1;
84 17 ▶ $self->{model} = 'SH2101V' if $1 eq 'MST_v_SH2101V'; # Huh?
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq "MST_v_SH2101V" 1 16 17
85  
86 17 ▶ if ($foma =~ s/^\((.*?)\)$//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($foma =~ s/^\((.*?)\)$//) 16 1 17
87 16 my @options = split /;/, $1;
88 16 for (@options) {
89 21 ▶ /^c(\d+)$/ and $self->{cache_size} = $1, next;
Branch: 1 branch
BranchTrueFalseTotal
/^c(\d+)$/ and $self->{"cache_size"} = $1, next 16 5 21
90 5 ▶ /^ser(\w{15})$/ and $self->{serial_number} = $1, next;
Branch: 1 branch
BranchTrueFalseTotal
/^ser(\w{15})$/ and $self->{"serial_number"} = $1, next 2 3 5
91 3 ▶ /^icc(\w{20})$/ and $self->{card_id} = $1, next;
Branch: 1 branch
BranchTrueFalseTotal
/^icc(\w{20})$/ and $self->{"card_id"} = $1, next 2 1 3
92 1 ▶ /^(T[CDBJ])$/ and $self->{status} = $1, next;
Branch: 1 branch
BranchTrueFalseTotal
/^(T[CDBJ])$/ and $self->{"status"} = $1, next 1 0 1
93 0 ▶ /^W(\d+)H(\d+)$/ and $self->{display_bytes} = "$1*$2", next;
Branch: 1 branch
BranchTrueFalseTotal
/^W(\d+)H(\d+)$/ and $self->{"display_bytes"} = "$1*$2", next 0 0 0
94 0 $self->no_match;
95 }
96 }
97 }
98  
99 sub html_version {
100 32 ▶ my $self = shift;
Subroutine html_version: called CC=3 SCAR=11.3
Pod documented
101  
102 32 my @map = @$HTMLVerMap;
103 32 ▶ while (my($re, $version) = splice(@map, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@map, 0, 2)) 111 0 111
104 111 ▶ return $version if $self->model =~ /$re/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->model =~ /$re/ 32 79 111
105 }
106 0 return undef;
107 }
108  
109 sub cache_size {
110 32 ▶ my $self = shift;
Subroutine cache_size: called CC=2 SCAR=7.1
Pod documented
111 32 ▶ return $self->{cache_size} || $DefaultCacheSize;
Condition66%2/3
$self->{'cache_size'} || $HTTP::MobileAgent::DoCoMo::DefaultCacheSize
l!l&&r!l&&!r
2930
MC/DC0%0/2
$self->{'cache_size'} || $HTTP::MobileAgent::DoCoMo::DefaultCacheSize
$self->{'cache_size'} $HTTP::MobileAgent::DoCoMo::DefaultCacheSize
Truth table66%2/3
A || B
A= $self->{'cache_size'}B= $HTTP::MobileAgent::DoCoMo::DefaultCacheSize
ABresult
1X1
011
000
112 }
113  
114 sub series {
115 32 ▶ my $self = shift;
Subroutine series: called CC=3 SCAR=11.0
Pod documented
116 32 my $model = $self->model;
117  
118 32 ▶ if ($self->is_foma && $model =~ /\d{4}/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_foma and $model =~ /\d{4}/) 9 23 32
Condition66%2/3
$self->is_foma and $model =~ /\d{4}/
!ll&&!rl&&r
2309
MC/DC50%1/2
$self->is_foma and $model =~ /\d{4}/
$self->is_foma $model =~ /\d{4}/
Truth table66%2/3
A and B
A= $self->is_fomaB= $model =~ /\d{4}/
ABresult
0X0
100
111
119 9 return 'FOMA';
120 }
121  
122 23 $model =~ /(\d{3}i)/;
123 23 return $1;
124 }
125  
126 sub vendor {
127 32 ▶ my $self = shift;
Subroutine vendor: called CC=1 SCAR=0.0
Pod documented
128 32 my $model = $self->model;
129 32 $model =~ /^([A-Z]+)\d/;
130 32 return $1;
131 }
132  
133 sub _make_display {
134 4 ▶ my $self = shift;
Subroutine _make_display: called CC=2 SCAR=6.9
135 4 my $display = $DisplayMap->{uc($self->model)};
136 4 ▶ if ($self->{display_bytes}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"display_bytes"}) 1 3 4
137 1 my($w, $h) = split /\*/, $self->{display_bytes};
138 1 $display->{width_bytes} = $w;
139 1 $display->{height_bytes} = $h;
140 }
141 4 return HTTP::MobileAgent::Display->new(%$display);
142 }
143  
144 sub is_gps {
145 1 ▶ my $self = shift;
Subroutine is_gps: called CC=1 SCAR=0.0
Pod undocumented
146 1 return exists $GPSModels->{$self->model};
147 }
148  
149 9 1;
150 __END__
↑ Summary MobileAgent/DoCoMoDisplayMap.pm »