blib/lib/Jcode.pm

filter: Statementstmt 93.1% 313 / 336 Branchbran 72.3% 107 / 148 Conditioncond 62.9% 34 / 54 MC/DCmcdc 25.8% 8 / 31 Subroutinesub 94.0% 47 / 50 Podpod 100% 17 / 17 totaltotal 82.7% 526 / 636 CC 94 SCAR 20.8
CC
94
Cov
84%
getcode
19.9
jfold
15.6
convert
11.3
CRAP 8.0
↑ Summary
1 #
2 # $Id: Jcode.pm,v 2.7 2008/05/10 18:15:19 dankogai Exp dankogai $
3 #
4  
5 package Jcode;
6 11 ▶use 5.005; # fair ?
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use vars qw($RCSID $VERSION $DEBUG);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 $RCSID = q$Id: Jcode.pm,v 2.7 2008/05/10 18:15:19 dankogai Exp dankogai $;
12 11 $VERSION = do { my @r = (q$Revision: 2.7 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
13 11 $DEBUG = 0;
14  
15 # we no longer use Exporter
16 11 ▶use vars qw($USE_ENCODE);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 $USE_ENCODE = ($] >= 5.008001);
18  
19 11 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 11 ▶use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 11 @ISA = qw(Exporter);
22 11 @EXPORT = qw(jcode getcode);
23 11 @EXPORT_OK = qw($RCSID $VERSION $DEBUG);
24 11 %EXPORT_TAGS = ( all => [ @EXPORT, @EXPORT_OK ] );
25  
26 use overload
27 23 ▶ q("") => sub { $_[0]->euc },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
28 0 ▶ q(==) => sub { overload::StrVal($_[0]) eq overload::StrVal($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
29 25 ▶ q(.=) => sub { $_[0]->append( $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
30 11 fallback => 1,
31 11 ;
32  
33 11 ▶if ($USE_ENCODE){
Branch: 1 branch
BranchTrueFalseTotal
if ($Jcode::USE_ENCODE) { } 11 0 11
34 11 ▶ $DEBUG and warn "Using Encode";
Branch: 1 branch
BranchTrueFalseTotal
$Jcode::DEBUG and warn "Using Encode" 0 11 11
35 11 my $data = join("", <DATA>);
36 0 ▶ eval $data;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine AUTOLOAD: called CC=5 SCAR=16.2
Subroutine DESTROY: not called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=2 SCAR=7.0
Subroutine __ANON__: called CC=2 SCAR=7.0
Subroutine _add_encoded_word: called CC=6 SCAR=18.1
Subroutine _max: called CC=3 SCAR=11.1
Subroutine _mime_unstructured_header: called CC=8 SCAR=21.0
Subroutine append: called CC=8 SCAR=21.0
Subroutine convert: called CC=11 SCAR=24.3
Subroutine fallback: called CC=2 SCAR=7.0
Subroutine getcode: called CC=19 SCAR=29.9
Subroutine h2z: called CC=1 SCAR=0.0
Subroutine jcode: called CC=1 SCAR=0.0
Subroutine jfold: called CC=15 SCAR=27.5
Subroutine jlength: called CC=1 SCAR=0.0
Subroutine m: called CC=5 SCAR=16.2
Subroutine mime_decode: called CC=1 SCAR=0.0
Subroutine mime_encode: called CC=4 SCAR=14.0
Subroutine new: called CC=2 SCAR=7.0
Subroutine s: called CC=4 SCAR=14.0
Subroutine set: called CC=8 SCAR=21.0
Subroutine tr: called CC=6 SCAR=18.1
Subroutine utf8: called CC=1 SCAR=0.0
Subroutine z2h: called CC=1 SCAR=0.0
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Branch: 70 branches
BranchTrueFalseTotal
my $type = ref $self or confess("$self is not an object") 1 0 1
$myname eq "DESTROY" and return 0 1 1
my $e = &find_encoding($myname) or confess(__PACKAGE__, ": unknown encoding: $myname") 1 0 1
$Jcode::DEBUG and warn ref $self, "->$myname defined" 0 1 1
&Encode::is_utf8($$r_str) ? : 130 0 130
&Encode::is_utf8($str) ? : 1 0 1
if (length $str) 12 8 20
if (length($line) + 22 + $target =~ /^(?:$RE{"EUC_0212"}|$RE{"EUC_C"})/o * 8 > $bpl) 4 8 12
if (my $count = $iso_2022_jp =~ tr/\200-\377//d) 0 32 32
$Jcode::DEBUG and warn $count 0 0 0
if (length($encoded) + length($line) > $bpl) { } 20 12 32
if $n > $result 61 49 110
if ($i < $#wordstmp) 8 12 20
if (not $wordstmp[$i] =~ /^[\x21-\x7E]+$/ || $wordstmp[$i + 1] =~ /^[\x21-\x7E]+$/) { } 0 8 8
if ($word =~ /^[\x21-\x7E]+$/) { } 12 8 20
if (length($1) + length($word) > $bpl) { } 0 12 12
if (length $1 == $bpl) { } 0 20 20
ref $str ? : 0 50 50
if defined $_[1] 25 25 50
unless (&Encode::is_utf8($$r_str) or $icode eq "binary") 50 0 50
ref $_[0] ? : 41 42 83
&Encode::is_utf8($$r_str) and utf8::encode($$r_str) 0 83 83
defined $icode or $icode = getcode($r_str) or return 83 0 83
$icode eq "binary" and return $$r_str 0 83 83
$jname2e{$icode} and $icode = $jname2e{$icode} 65 18 83
$jname2e{$ocode} and $ocode = $jname2e{$ocode} 65 18 83
if ($opt) { } 0 83 83
$opt eq 'z' ? : 0 0 0
if (&Scalar::Util::readonly($$r_str)) { } 1 82 83
@_ or return $self->{"fallback"} 3 0 3
ref $arg ? : 92 0 92
&Encode::is_utf8($$r_str) and return "utf8" 2 90 92
if ($$r_str =~ /$RE{'BIN'}/o) { } 7 83 90
elsif (not $$r_str =~ /[\e\x80-\xff]/o) { } 21 62 83
elsif ($$r_str =~ / $RE{'JIS_0208'}|$RE{'JIS_0212'}|$RE{'JIS_ASC'}|$RE{'JIS_KANA'} /ox) { } 7 55 62
$$r_str =~ /(\x00$RE{"ASCII"})+/go and do { $ucs2 += length $1 } 2098 7 2105
if ($ucs2) { } 7 0 7
$$r_str =~ /((?:$RE{"SJIS_C"})+)/go and do { $sjis += length $1 } 36147 55 36202
$$r_str =~ /((?:$RE{"EUC_C"}|$RE{"EUC_KANA"}|$RE{"EUC_0212"})+)/go and do { $euc += length $1 } 25308 55 25363
$$r_str =~ /((?:$RE{"UTF8"})+)/go and do { $utf8 += length $1 } 5791 55 5846
if $Jcode::DEBUG >= 3 0 55 55
$euc > $sjis && $euc > $utf8 ? : 42 13 55
$sjis > $euc && $sjis > $utf8 ? : 6 7 13
$utf8 > $euc && $utf8 > $sjis ? : 7 0 7
wantarray ? : 0 90 90
if (defined $kin and ref $kin eq "ARRAY") 3 3 6
&Encode::is_utf8($_) ? : 0 12 12
if ($$r_str =~ /(.)/gs) 107 6 113
$ord < 128 ? : 27 80 107
$ord < 65377 ? : 60 20 80
$ord <= 65439 ? : 20 0 20
if ($len + $clen > $bpl) 18 89 107
unless ($kinsoku{$char}) 13 5 18
defined $lines[$i] or pop @lines 6 0 6
&Encode::is_utf8($_) ? : 19 0 19
wantarray ? : 1 5 6
&Encode::is_utf8($_[0]) ? : 0 3 3
if ($@) 1 2 3
wantarray ? : 1 1 2
$trailing_crlf or $str =~ s/(\n|\r|\x0d\x0a)$//o 6 6 12
defined $_[0] or $_[0] = "" 184 0 184
&Encode::is_utf8($_[0]) ? : 0 5 5
&Encode::is_utf8($_[0]) ? : 0 5 5
if ($@) 1 4 5
ref $str ? : 8 198 206
if defined $_[1] 148 58 206
unless (&Encode::is_utf8($$r_str) or $icode eq "binary") 196 10 206
&Encode::is_utf8($_[0]) ? : 0 10 10
&Encode::is_utf8($_[1]) ? : 0 10 10
if ($@) 1 9 10
Condition62%34/54
$wordstmp[$i] =~ /^[\x21-\x7E]+$/ || $wordstmp[$i + 1] =~ /^[\x21-\x7E]+$/
l!l&&r!l&&!r
440
$code || getcode($r_str) || 'euc'
l!l
500
$code or getcode($r_str)
l!l&&r!l&&!r
25250
$jname2e{$icode} || $icode
l!l&&r!l&&!r
40100
&Encode::is_utf8($$r_str) or $icode eq "binary"
l!l&&r!l&&!r
0050
defined $icode or $icode = getcode($r_str)
l!l&&r!l&&!r
8300
$euc > $sjis and $euc > $utf8
!ll&&!rl&&r
13042
$sjis > $euc and $sjis > $utf8
!ll&&!rl&&r
076
$utf8 > $euc and $utf8 > $sjis
!ll&&!rl&&r
007
shift() || 72
l!l
60
shift() || "\n"
l!l
51
defined $kin and ref $kin eq "ARRAY"
!ll&&!rl&&r
303
shift() || ''
l!l
12
shift() || "\n"
l!l
012
shift() || 76
l!l
012
$code || getcode($r_str) || 'euc'
l!l
2060
$code or getcode($r_str)
l!l&&r!l&&!r
148580
$jname2e{$icode} || $icode
l!l&&r!l&&!r
152540
&Encode::is_utf8($$r_str) or $icode eq "binary"
l!l&&r!l&&!r
100196
$_[2] || ''
l!l
28
$match || 0
l!l
81
MC/DC0%0/2
$wordstmp[$i] =~ /^[\x21-\x7E]+$/ || $wordstmp[$i + 1] =~ /^[\x21-\x7E]+$/
$wordstmp[$i] =~ /^[\x21-\x7E]+$/ $wordstmp[$i + 1] =~ /^[\x21-\x7E]+$/
MC/DC0%0/2
$code || getcode($r_str) || 'euc'
$code getcode($r_str)
MC/DC0%0/2
$jname2e{$icode} || $icode
$jname2e{$icode} $icode
MC/DC0%0/2
&Encode::is_utf8($$r_str) or $icode eq "binary"
&Encode::is_utf8($$r_str) $icode eq "binary"
MC/DC0%0/2
defined $icode or $icode = getcode($r_str)
defined $icode $icode = getcode($r_str)
MC/DC50%1/2
$euc > $sjis and $euc > $utf8
$euc > $sjis $euc > $utf8
MC/DC50%1/2
$sjis > $euc and $sjis > $utf8
$sjis > $euc $sjis > $utf8
MC/DC0%0/2
$utf8 > $euc and $utf8 > $sjis
$utf8 > $euc $utf8 > $sjis
MC/DC0%0/1
shift() || 72
shift()
MC/DC100%1/1
shift() || "\n"
shift()
MC/DC50%1/2
defined $kin and ref $kin eq "ARRAY"
defined $kin ref $kin eq "ARRAY"
MC/DC100%1/1
shift() || ''
shift()
MC/DC0%0/1
shift() || "\n"
shift()
MC/DC0%0/1
shift() || 76
shift()
MC/DC0%0/2
$code || getcode($r_str) || 'euc'
$code getcode($r_str)
MC/DC0%0/2
$jname2e{$icode} || $icode
$jname2e{$icode} $icode
MC/DC50%1/2
&Encode::is_utf8($$r_str) or $icode eq "binary"
&Encode::is_utf8($$r_str) $icode eq "binary"
MC/DC100%1/1
$_[2] || ''
$_[2]
MC/DC100%1/1
$match || 0
$match
Truth table66%2/3
A || B
A= $wordstmp[$i] =~ /^[\x21-\x7E]+$/B= $wordstmp[$i + 1] =~ /^[\x21-\x7E]+$/
ABresult
1X1
011
000
Truth table66%2/3
A or B
A= $codeB= getcode($r_str)
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $jname2e{$icode}B= $icode
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= &Encode::is_utf8($$r_str)B= $icode eq "binary"
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= defined $icodeB= $icode = getcode($r_str)
ABresult
1X1
011
000
Truth table66%2/3
A and B
A= $euc > $sjisB= $euc > $utf8
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= $sjis > $eucB= $sjis > $utf8
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= $utf8 > $eucB= $utf8 > $sjis
ABresult
0X0
100
111
Truth table50%1/2
A
A= shift()
Aresult
11
00
Truth table100%2/2
A
A= shift()
Aresult
11
00
Truth table66%2/3
A and B
A= defined $kinB= ref $kin eq "ARRAY"
ABresult
0X0
100
111
Truth table100%2/2
A
A= shift()
Aresult
11
00
Truth table50%1/2
A
A= shift()
Aresult
11
00
Truth table50%1/2
A
A= shift()
Aresult
11
00
Truth table66%2/3
A or B
A= $codeB= getcode($r_str)
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $jname2e{$icode}B= $icode
ABresult
1X1
011
000
Truth table66%2/3
A or B
A= &Encode::is_utf8($$r_str)B= $icode eq "binary"
ABresult
1X1
011
000
Truth table100%2/2
A
A= $_[2]
Aresult
11
00
Truth table100%2/2
A
A= $match
Aresult
11
00
37 11 ▶ $@ and die $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and die $@ 0 11 11
38 }else{
39 0 ▶ $DEBUG and warn "Not Using Encode";
Branch: 1 branch
BranchTrueFalseTotal
$Jcode::DEBUG and warn "Not Using Encode" 0 0 0
40 0 require Jcode::_Classic;
41 11 ▶ use vars qw/@ISA/;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 0 unshift @ISA, qw/Jcode::_Classic/;
43 0 for my $sub (qw/jcode getcode convert load_module/){
44 11 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
45 0 *{$sub} = \&{'Jcode::_Classic::' . $sub };
46 }
47 0 for my $enc (qw/sjis jis ucs2 utf8/){
48 11 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
49 0 *{"euc_" . $enc} = \&{"Jcode::_Classic::" . "euc_" . $enc};
50 0 *{$enc . "_euc"} = \&{"Jcode::_Classic::" . $enc . "_euc"};
51 }
52 }
53  
54 11 1;
55 __DATA__
↑ Summary