| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 40 | } (wantarray ? @_ : $_[0]); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 3 | ▶ | wantarray ? @str : $str[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 6 | my $chr = shift; | |||||||||||||||||||||||||||
| 58 | 6 | my $ord = ord $chr; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 6 | ▶ | return "\\\\" if $chr eq "\\"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 6 | ▶ | if ($Names and my $name = charnames::viacode($ord)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Unicode::Debug::Names and my $name = charnames::viacode($ord)
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)
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||