blib/lib/EBook/Ishmael/CharDet/ISO2022.pm

filter: Statementstmt 80.0% 40 / 50 Branchbran 83.3% 10 / 12 Conditioncond 66.6% 6 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 76.9% 10 / 13 Podpod 0.0% 0 / 6 totaltotal 71.8% 69 / 96 CC 11 SCAR 16.7
CC
11
Cov
79%
take
10.4
confidence
2.1
new
2.0
CRAP 5.3
« blib/lib/EBook/Ishmael/CharDet/ShiftJIS.pm ↑ Summary blib/lib/EBook/Ishmael/EBook/PalmDoc.pm »
1 package EBook::Ishmael::CharDet::ISO2022;
2 18 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 18 our $VERSION = '2.03';
4 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 18 ▶use EBook::Ishmael::CharDet::Constants qw(:CONSTANTS);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 18 ▶use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 use constant {
12 18 STATE_UNKNOWN => 0,
13 STATE_GOOD => 1,
14 STATE_BAD => 2,
15 18 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 sub initialize {
18  
19 46 ▶ my ($self) = @_;
Subroutine initialize: called CC=1 SCAR=0.0
Pod undocumented
20  
21 46 %$self = (
22 InEscape => 0,
23 Cur => '',
24 State => STATE_UNKNOWN,
25 Unique => [],
26 );
27  
28 }
29  
30 sub new {
31  
32 0 ▶ my ($class) = @_;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
33  
34 0 my $self = bless {}, $class;
35 0 $self->initialize;
36  
37 0 return $self;
38  
39 }
40  
41 sub take {
42  
43 17528 ▶ my ($self, $data) = @_;
Subroutine take: called CC=10 SCAR=23.4
Pod undocumented
44  
45 17528 for my $i (0 .. length($data) - 1) {
46 280411 my $b = ord(substr $data, $i, 1) & 0xff;
47 280411 ▶ if (!$self->{InEscape} && $b == ord "\e") {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->{'InEscape'} and $b == 27) { } 6 280405 280411
elsif ($self->{'InEscape'}) { } 16 280389 280405
Condition100%3/3
not $self->{"InEscape"} and $b == 27
!ll&&!rl&&r
162803896
MC/DC100%2/2
not $self->{"InEscape"} and $b == 27
not $self->{"InEscape"} $b == 27
Truth table100%3/3
not(A) and B
A= not $self->{"InEscape"}B= $b == 27
ABresult
0X0
100
111
48 6 $self->{InEscape} = 1;
49 } elsif ($self->{InEscape}) {
50 16 ▶ if ($b >= 0x20 && $b <= 0x2f) {
Branch: 2 branches
BranchTrueFalseTotal
if ($b >= 32 and $b <= 47) { } 10 6 16
elsif ($b >= 48 and $b <= 126) { } 6 0 6
Condition66%2/3
$b >= 32 and $b <= 47
!ll&&!rl&&r
0610
MC/DC50%1/2
$b >= 32 and $b <= 47
$b >= 32 $b <= 47
Truth table66%2/3
A and B
A= $b >= 32B= $b <= 47
ABresult
0X0
100
111
51 10 $self->{Cur} .= chr $b;
52 ▶ } elsif ($b >= 0x30 && $b <= 0x7e) {
Condition33%1/3
$b >= 48 and $b <= 126
!ll&&!rl&&r
006
MC/DC0%0/2
$b >= 48 and $b <= 126
$b >= 48 $b <= 126
Truth table33%1/3
A and B
A= $b >= 48B= $b <= 126
ABresult
0X0
100
111
53 6 $self->{Cur} .= chr $b;
54 6 $self->{InEscape} = 0;
55 6 ▶ if (any { $_ eq $self->{Cur} } @{ $self->{Unique} }) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $_ eq $self->{"Cur"}; } , @{$$self{"Unique"};})) 4 2 6
56 4 $self->{State} = STATE_GOOD;
57 4 return TAKE_MUST_BE;
58 }
59 2 $self->{Cur} = '';
60 } else {
61 0 $self->{State} = STATE_BAD;
62 0 return TAKE_BAD;
63 }
64 }
65 }
66  
67 17524 return TAKE_OK;
68  
69 }
70  
71 sub confidence {
72  
73 34 ▶ my ($self) = @_;
Subroutine confidence: called CC=2 SCAR=7.6
Pod undocumented
74  
75 34 ▶ if ($self->{State} == STATE_GOOD) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'State'} == 1) { } 0 34 34
76 0 return 1.0;
77 } else {
78 34 return 0;
79 }
80  
81 }
82  
83 sub bad {
84  
85 0 ▶ my ($self) = @_;
Subroutine bad: not called CC=1 SCAR=6.9
Pod undocumented
86  
87 0 return $self->{State} == STATE_BAD;
88  
89 }
90  
91 0 ▶sub encoding { die "encoding not set" }
Subroutine encoding: not called CC=1 SCAR=6.9
Pod undocumented
92  
93 18 1;
« blib/lib/EBook/Ishmael/CharDet/ShiftJIS.pm ↑ Summary blib/lib/EBook/Ishmael/EBook/PalmDoc.pm »