blib/lib/CCCP/Encode.pm

filter: Statementstmt 50.0% 22 / 44 Branchbran 4.5% 1 / 22 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 66.6% 4 / 6 Podpod 100% 1 / 1 totaltotal 32.5% 28 / 86 CC 14 SCAR 50.4
CC
14
Cov
31%
utf2cyrillic
210.0
__err_msg
2.0
BEGIN
1.0
CRAP 155.1
↑ Summary
1 package CCCP::Encode;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Text::Unidecode;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = '0.03';
10  
11 1 $CCCP::Encode::ToText = 0;
12 1 $CCCP::Encode::Entities = 'xml';
13 1 $CCCP::Encode::CharMap = {};
14 1 $CCCP::Encode::Regexp = '[^\p{Cyrillic}|\p{IsLatin}|\p{InBasic_Latin}]';
15  
16 1 my $xml_entities = {
17 '&' => '&',
18 '"' => '"',
19 "'" => ''',
20 '>' => '>',
21 '<' => '&lt;'
22 };
23  
24 1 my $f = find_encoding('utf-8');
25 1 my $t = undef;
26 1 ▶__err_msg("Unknown encoding 'utf-8'") unless defined $f;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f 0 1 1
27  
28 0 ▶sub utf2cyrillic {
Subroutine utf2cyrillic: not called CC=14 SCAR=53.5
Pod documented
29 0 my ( $class, $str, $to ) = @_;
30
31 0 ▶ if ($CCCP::Encode::ToText and not UNIVERSAL::isa($CCCP::Encode::CharMap,'HASH') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CCCP::Encode::ToText and not UNIVERSAL::isa($CCCP::Encode::CharMap, "HASH")) 0 0 0
Condition0%0/3
$CCCP::Encode::ToText and not UNIVERSAL::isa($CCCP::Encode::CharMap, "HASH")
!ll&&!rl&&r
000
MC/DC0%0/2
$CCCP::Encode::ToText and not UNIVERSAL::isa($CCCP::Encode::CharMap, "HASH")
$CCCP::Encode::ToText not UNIVERSAL::isa($CCCP::Encode::CharMap, "HASH")
Truth table0%0/3
A and not(B)
A= $CCCP::Encode::ToTextB= not UNIVERSAL::isa($CCCP::Encode::CharMap, "HASH")
ABresult
0X0
100
111
32 0 __err_msg("\$CCCP::Encode::CharMap must be hash ref");
33 };
34
35 0 ▶ return undef unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 0 0
36
37 0 ▶ __err_msg("missing 'to' argument") unless $to;
Branch: 1 branch
BranchTrueFalseTotal
unless $to 0 0 0
38 0 ▶ return $str if ($to =~ /^utf/i);
Branch: 1 branch
BranchTrueFalseTotal
if $to =~ /^utf/i 0 0 0
39  
40 0 ▶ $t = find_encoding($to) unless ($t and $t->name eq $to);
Branch: 1 branch
BranchTrueFalseTotal
unless $t and $t->name eq $to 0 0 0
Condition0%0/3
$t and $t->name eq $to
!ll&&!rl&&r
000
MC/DC0%0/2
$t and $t->name eq $to
$t $t->name eq $to
Truth table0%0/3
A and B
A= $tB= $t->name eq $to
ABresult
0X0
100
111
41 0 ▶ __err_msg("Unknown encoding '$to'") unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 0 0
42
43 0 Encode::_utf8_off($str);
44
45 0 ▶ unless ($CCCP::Encode::ToText) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CCCP::Encode::ToText) { } 0 0 0
46 # decode with html entities
47 0 ▶ $CCCP::Encode::Entities ||= 'xml';
Condition0%0/2
$CCCP::Encode::Entities ||= "xml"
l!l
00
MC/DC0%0/1
$CCCP::Encode::Entities ||= "xml"
$CCCP::Encode::Entities
Truth table0%0/2
A
A= $CCCP::Encode::Entities
Aresult
11
00
48 0 ▶ my $str = $t->encode($f->decode($str), $CCCP::Encode::Entities eq 'xml' ? Encode::FB_XMLCREF : Encode::FB_HTMLCREF);
Branch: 1 branch
BranchTrueFalseTotal
$CCCP::Encode::Entities eq 'xml' ? : 0 0 0
49 0 ▶ if ($CCCP::Encode::Entities eq 'xml') {
Branch: 1 branch
BranchTrueFalseTotal
if ($CCCP::Encode::Entities eq "xml") 0 0 0
50 0 $str =~ s/('|"|<|>|&(?!#x))/$xml_entities->{$1}/geo;
51 };
52 0 return $str;
53 } else {
54 # decode in text mode
55 0 ▶ ($str = $f->decode($str)) =~ s/($CCCP::Encode::Regexp)/exists $CCCP::Encode::CharMap->{$1} ? $CCCP::Encode::CharMap->{$1} : unidecode($1)/sexg;
Branch: 1 branch
BranchTrueFalseTotal
exists $CCCP::Encode::CharMap->{$1} ? : 0 0 0
56 0 return $t->encode($str);
57 };
58 }
59  
60 0 ▶sub __err_msg {
Subroutine __err_msg: not called CC=1 SCAR=6.9
61 0 my ($str) = @_;
62
63 0 require Carp;
64 0 Carp::croak(__PACKAGE__.": ".$str);
65 }
66  
67 1 1;
68 __END__
↑ Summary