blib/lib/Catalyst/Controller/Mobile/JP.pm

filter: Statementstmt 98.2% 57 / 58 Branchbran 64.2% 9 / 14 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 1 totaltotal 78.8% 82 / 104 CC 14 SCAR 18.4
CC
14
Cov
83%
begin
12.7
end
4.2
__ANON__
2.0
CRAP 6.3
↑ Summary
1 package Catalyst::Controller::Mobile::JP;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 our $VERSION = '0.02';
5  
6 4 ▶use base qw( Catalyst::Controller Class::Accessor::Fast );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 __PACKAGE__->mk_accessors(qw( encoding ));
8  
9 4 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Encode::JP::Mobile ':props';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Encode::JP::Mobile::Character;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use HTTP::MobileAgent::Plugin::Charset;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 8 ▶sub begin :Private {
Subroutine begin: called CC=10 SCAR=25.4
15 8 my ($self, $c) = @_;
16
17 8 $self->encoding(do {
18 8 my $encoding = $c->req->mobile_agent->encoding;
19 8 ▶ ref($encoding) && $encoding->isa('Encode::Encoding')
Branch: 1 branch
BranchTrueFalseTotal
ref $encoding && $encoding->isa('Encode::Encoding') ? : 0 8 8
Condition33%1/3
ref $encoding and $encoding->isa("Encode::Encoding")
!ll&&!rl&&r
800
MC/DC0%0/2
ref $encoding and $encoding->isa("Encode::Encoding")
ref $encoding $encoding->isa("Encode::Encoding")
Truth table33%1/3
A and B
A= ref $encodingB= $encoding->isa("Encode::Encoding")
ABresult
0X0
100
111
20 ? $encoding
21 : Encode::find_encoding($encoding);
22 });
23
24 8 for my $value (values %{ $c->req->{parameters} }) {
25 5 ▶ next if ref $value && ref $value ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value and ref $value ne "ARRAY" 0 5 5
Condition33%1/3
ref $value and ref $value ne "ARRAY"
!ll&&!rl&&r
500
MC/DC0%0/2
ref $value and ref $value ne "ARRAY"
ref $value ref $value ne "ARRAY"
Truth table33%1/3
A and B
A= ref $valueB= ref $value ne "ARRAY"
ABresult
0X0
100
111
26
27 5 ▶ for my $v (ref($value) ? @$value : $value) {
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 0 5 5
28 5 ▶ next if Encode::is_utf8($v);
Branch: 1 branch
BranchTrueFalseTotal
if &Encode::is_utf8($v) 5 0 5
29 0 $v = $self->encoding->decode($v);
30 }
31 }
32
33 8 $c->res->content_type(do {
34 8 ▶ if ($c->req->mobile_agent->is_docomo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->req->mobile_agent->is_docomo) { } 4 4 8
35 4 'application/xhtml+xml';
36 } else {
37 4 'text/html; charset=' . $self->encoding->mime_name;
38 }
39 });
40 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 4 my %htmlspecialchars = ( '&' => '&amp;', '<' => '&lt;', '>' => '&gt;', '"' => '&quot;' );
43 4 my $htmlspecialchars = join '', keys %htmlspecialchars;
44  
45 4 our $decoding_content_type = qr{^text|xml$|javascript$};
46  
47 8 ▶sub end :Private {
Subroutine end: called CC=4 SCAR=14.4
Pod undocumented
48 8 my ($self, $c) = @_;
49
50 8 my $body = $c->res->body;
51 8 ▶ if ($body and
Branch: 1 branch
BranchTrueFalseTotal
if ($body and not ref $body and $c->res->content_type =~ /$Catalyst::Controller::Mobile::JP::decoding_content_type/) 8 0 8
Condition33%2/6
$body and not ref $body and $c->res->content_type =~ /$Catalyst::Controller::Mobile::JP::decoding_content_type/
!ll&&!rl&&r
008
$body and not ref $body
!ll&&!rl&&r
008
MC/DC0%0/3
$body and not ref $body and $c->res->content_type =~ /$Catalyst::Controller::Mobile::JP::decoding_content_type/
$body not ref $body $c->res->content_type =~ /$Catalyst::Controller::Mobile::JP::decoding_content_type/
Truth table25%1/4
A and not(B) and C
A= $bodyB= not ref $bodyC= $c->res->content_type =~ /$Catalyst::Controller::Mobile::JP::decoding_content_type/
ABCresult
0XX0
10X0
1100
1111
52 not ref($body) and
53 $c->res->content_type =~ $decoding_content_type) {
54
55 8 ▶ $body = $self->encoding->encode($body, sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
56 8 my $char = shift;
57 8 my $out = Encode::JP::Mobile::FB_CHARACTER()->($char);
58
59 8 ▶ if ($c->res->content_type =~ /html$|xml$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->res->content_type =~ /html$|xml$/) 1 7 8
60 1 $out =~ s/([$htmlspecialchars])/$htmlspecialchars{$1}/ego; # for (>3<)
61 }
62  
63 8 $out;
64 8 });
65
66 8 $c->res->body($body);
67 }
68 4 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
69  
70 4 1;
71 __END__
↑ Summary