Unicode/Debug.pm

filter: Statementstmt 100% 45 / 45 Branchbran 71.4% 10 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 91.8% 68 / 74 CC 10 SCAR 13.5
CC
10
Cov
92%
_char
6.2
unidecode
5.1
BEGIN
1.0
CRAP 3.8
« Devel/Unicode.pm ↑ Summary PerlIO/via/UnicodeDebug.pm »
1 package Unicode::Debug;
2  
3 3 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use charnames ':full';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 BEGIN
10 3 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 $Unicode::Debug::AUTHORITY = 'cpan:TOBYINK';
12 3 $Unicode::Debug::VERSION = '0.002';
13 }
14  
15 3 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 our @ISA = qw( Exporter );
17 3 our @EXPORT = qw( unidebug );
18 3 our @EXPORT_OK = ( @EXPORT, qw(unidecode) );
19 3 our %EXPORT_TAGS = (
20 default => \@EXPORT,
21 standard => \@EXPORT,
22 all => \@EXPORT_OK,
23 nothing => [],
24 );
25  
26 3 our $Whitespace = 0;
27 3 our $Names = 0;
28  
29 sub unidecode
30 4 ▶{
Subroutine unidecode: called CC=5 SCAR=16.2
Pod documented
31 4 ▶ unless (defined wantarray)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 1 3 4
32 {
33 1 s/(\r\n|[^\x20-\x7F])/_char($1)/eg for @_;
34 1 return;
35 }
36
37 my @str = map {
38 3 (my $str = $_) =~ s/(\r\n|\\|[^\x20-\x7F])/_char($1)/eg;
39 3 ▶ $str;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
40 } (wantarray ? @_ : $_[0]);
41
42 3 ▶ wantarray ? @str : $str[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
43 }
44  
45 3 my %wschars = (
46 "\r\n" => "\\r\\n\n",
47 "\r" => "\\r\n",
48 "\n" => "\\n\n",
49 "\t" => "\\t",
50 );
51  
52 sub _char
53 8 ▶{
Subroutine _char: called CC=6 SCAR=18.2
54 return $Whitespace ? $wschars{$_[0]} : $_[0]
55 8 ▶ if exists $wschars{$_[0]};
Branch: 2 branches
BranchTrueFalseTotal
if exists $wschars{$_[0]} 2 6 8
$Unicode::Debug::Whitespace ? : 2 0 2
56
57 6 my $chr = shift;
58 6 my $ord = ord $chr;
59
60 6 ▶ return "\\\\" if $chr eq "\\";
Branch: 1 branch
BranchTrueFalseTotal
if $chr eq "\\" 0 6 6
61
62 6 ▶ if ($Names and my $name = charnames::viacode($ord))
Branch: 1 branch
BranchTrueFalseTotal
if ($Unicode::Debug::Names and my $name = charnames::viacode($ord)) 2 4 6
Condition66%2/3
$Unicode::Debug::Names and my $name = charnames::viacode($ord)
!ll&&!rl&&r
402
MC/DC50%1/2
$Unicode::Debug::Names and my $name = charnames::viacode($ord)
$Unicode::Debug::Names my $name = charnames::viacode($ord)
Truth table66%2/3
A and B
A= $Unicode::Debug::NamesB= my $name = charnames::viacode($ord)
ABresult
0X0
100
111
63 {
64 2 return sprintf('\N{%s}', $name);
65 }
66
67 4 sprintf('\x{%04x}', $ord);
68 }
69  
70 3 *unidebug = \&unidecode;
71  
72 3 require PerlIO::via::UnicodeDebug;
73  
74 3 __PACKAGE__
75 __END__
« Devel/Unicode.pm ↑ Summary PerlIO/via/UnicodeDebug.pm »