| 1 | # | ||||||||||||||||||||||||||||
| 2 | # $Id: Encode.pm,v 3.25 2026/10/26 01:42:18 dankogai Exp $ | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | package Encode; | ||||||||||||||||||||||||||||
| 5 | 69 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 69 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 69 | ▶ | use constant DEBUG => !!$ENV{PERL_ENCODE_DEBUG}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 69 | our $VERSION; | |||||||||||||||||||||||||||
| 9 | 69 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 69 | $VERSION = '3.25'; | |||||||||||||||||||||||||||
| 11 | 69 | require XSLoader; | |||||||||||||||||||||||||||
| 12 | 69 | XSLoader::load( __PACKAGE__, $VERSION ); | |||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 69 | ▶ | use Exporter 5.57 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 69 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 69 | our @CARP_NOT = qw(Encode::Encoder); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # Public, encouraged API is exported by default | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 69 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 23 | decode decode_utf8 encode encode_utf8 str2bytes bytes2str | ||||||||||||||||||||||||||||
| 24 | encodings find_encoding find_mime_encoding clone_encoding | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | 69 | our @FB_FLAGS = qw( | |||||||||||||||||||||||||||
| 27 | DIE_ON_ERR WARN_ON_ERR RETURN_ON_ERR LEAVE_SRC | ||||||||||||||||||||||||||||
| 28 | PERLQQ HTMLCREF XMLCREF STOP_AT_PARTIAL | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | 69 | our @FB_CONSTS = qw( | |||||||||||||||||||||||||||
| 31 | FB_DEFAULT FB_CROAK FB_QUIET FB_WARN | ||||||||||||||||||||||||||||
| 32 | FB_PERLQQ FB_HTMLCREF FB_XMLCREF | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | 69 | our @EXPORT_OK = ( | |||||||||||||||||||||||||||
| 35 | qw( | ||||||||||||||||||||||||||||
| 36 | _utf8_off _utf8_on define_encoding from_to is_16bit is_8bit | ||||||||||||||||||||||||||||
| 37 | is_utf8 perlio_ok resolve_alias utf8_downgrade utf8_upgrade | ||||||||||||||||||||||||||||
| 38 | ), | ||||||||||||||||||||||||||||
| 39 | @FB_FLAGS, @FB_CONSTS, | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 69 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||
| 43 | all => [ @EXPORT, @EXPORT_OK ], | ||||||||||||||||||||||||||||
| 44 | default => [ @EXPORT ], | ||||||||||||||||||||||||||||
| 45 | fallbacks => [ @FB_CONSTS ], | ||||||||||||||||||||||||||||
| 46 | fallback_all => [ @FB_CONSTS, @FB_FLAGS ], | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # Documentation moved after __END__ for speed - NI-S | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 69 | our $ON_EBCDIC = ( ord("A") == 193 ); | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 69 | ▶ | use Encode::Alias (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | 69 | ▶ | use Encode::MIME::Name; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 69 | ▶ | use Storable; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # Make a %Encoding package variable to allow a certain amount of cheating | ||||||||||||||||||||||||||||
| 59 | 69 | our %Encoding; | |||||||||||||||||||||||||||
| 60 | 69 | our %ExtModule; | |||||||||||||||||||||||||||
| 61 | 69 | require Encode::Config; | |||||||||||||||||||||||||||
| 62 | # See | ||||||||||||||||||||||||||||
| 63 | # https://bugzilla.redhat.com/show_bug.cgi?id=435505#c2 | ||||||||||||||||||||||||||||
| 64 | # to find why sig handlers inside eval{} are disabled. | ||||||||||||||||||||||||||||
| 65 | 69 | eval { | |||||||||||||||||||||||||||
| 66 | 69 | local $SIG{__DIE__}; | |||||||||||||||||||||||||||
| 67 | 69 | local $SIG{__WARN__}; | |||||||||||||||||||||||||||
| 68 | 69 | local @INC = @INC; | |||||||||||||||||||||||||||
| 69 | 69 | ▶ | pop @INC if @INC && $INC[-1] eq '.'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@INC and $INC[-1] eq "."
MC/DC50%1/2
@INC and $INC[-1] eq "."
@INC
$INC[-1] eq "."
Truth table66%2/3
A and B
A= @INCB= $INC[-1] eq "."
| |||||||||||||||||||||||||||||
| 70 | 69 | require Encode::ConfigLocal; | |||||||||||||||||||||||||||
| 71 | }; | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 4 | ▶ | sub encodings { | ||||||||||||||||||||||||||
|
Subroutine
encodings: called CC=7 SCAR=22.7
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 4 | my %enc; | |||||||||||||||||||||||||||
| 75 | 4 | ▶ | my $arg = $_[1] || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$_[1] || ''
MC/DC100%1/1
$_[1] || ''
$_[1]
Truth table100%2/2
A
A= $_[1]
| |||||||||||||||||||||||||||||
| 76 | 4 | ▶ | if ( $arg eq ":all" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 3 | %enc = ( %Encoding, %ExtModule ); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||||||||||
| 80 | 1 | %enc = %Encoding; | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | for my $mod ( map { m/::/ ? $_ : "Encode::$_" } @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | DEBUG and warn $mod; | |||||||||||||||||||||||||||
| 83 | 0 | for my $enc ( keys %ExtModule ) { | |||||||||||||||||||||||||||
| 84 | 0 | ▶ | $ExtModule{$enc} eq $mod and $enc{$enc} = $mod; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 2152 | return sort { lc $a cmp lc $b } | |||||||||||||||||||||||||||
| 89 | 4 | grep { !/^(?:Internal|Unicode|Guess)$/o } keys %enc; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 16 | ▶ | sub perlio_ok { | ||||||||||||||||||||||||||
|
Subroutine
perlio_ok: called CC=3 SCAR=13.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 93 | 16 | ▶ | my $obj = ref( $_[0] ) ? $_[0] : find_encoding( $_[0] ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 16 | ▶ | $obj->can("perlio_ok") and return $obj->perlio_ok(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | return 0; # safety net | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1425 | ▶ | sub define_encoding { | ||||||||||||||||||||||||||
|
Subroutine
define_encoding: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 99 | 1425 | my $obj = shift; | |||||||||||||||||||||||||||
| 100 | 1425 | my $name = shift; | |||||||||||||||||||||||||||
| 101 | 1425 | $Encoding{$name} = $obj; | |||||||||||||||||||||||||||
| 102 | 1425 | my $lc = lc($name); | |||||||||||||||||||||||||||
| 103 | 1425 | ▶ | define_alias( $lc => $obj ) unless $lc eq $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 1425 | ▶ | while (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | my $alias = shift; | |||||||||||||||||||||||||||
| 106 | 0 | define_alias( $alias, $obj ); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | 1425 | my $class = ref($obj); | |||||||||||||||||||||||||||
| 109 | 1425 | ▶ | push @Encode::CARP_NOT, $class unless grep { $_ eq $class } @Encode::CARP_NOT; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 1425 | ▶ | push @Encode::Encoding::CARP_NOT, $class unless grep { $_ eq $class } @Encode::Encoding::CARP_NOT; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 1425 | return $obj; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 62714 | ▶ | sub getEncoding { | ||||||||||||||||||||||||||
|
Subroutine
getEncoding: called CC=13 SCAR=25.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 115 | 62714 | my ( $class, $name, $skip_external ) = @_; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 62714 | ▶ | defined($name) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 62695 | $name =~ s/\s+//g; # https://rt.cpan.org/Ticket/Display.html?id=65796 | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 62695 | ▶ | ref($name) && $name->can('renew') and return $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $name and $name->can("renew")
MC/DC50%1/2
ref $name and $name->can("renew")
ref $name
$name->can("renew")
Truth table66%2/3
A and B
A= ref $nameB= $name->can("renew")
| |||||||||||||||||||||||||||||
| 122 | 62683 | ▶ | exists $Encoding{$name} and return $Encoding{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 3714 | my $lc = lc $name; | |||||||||||||||||||||||||||
| 124 | 3714 | ▶ | exists $Encoding{$lc} and return $Encoding{$lc}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 3661 | my $oc = $class->find_alias($name); | |||||||||||||||||||||||||||
| 127 | 3661 | ▶ | defined($oc) and return $oc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 440 | ▶ | $lc ne $name and $oc = $class->find_alias($lc); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 440 | ▶ | defined($oc) and return $oc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 440 | ▶ | unless ($skip_external) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 440 | ▶ | if ( my $mod = $ExtModule{$name} || $ExtModule{$lc} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Encode::ExtModule{$name} || $Encode::ExtModule{$lc}
MC/DC50%1/2
$Encode::ExtModule{$name} || $Encode::ExtModule{$lc}
$Encode::ExtModule{$name}
$Encode::ExtModule{$lc}
Truth table66%2/3
A || B
A= $Encode::ExtModule{$name}B= $Encode::ExtModule{$lc}
| |||||||||||||||||||||||||||||
| 133 | 77 | $mod =~ s,::,/,g; | |||||||||||||||||||||||||||
| 134 | 77 | $mod .= '.pm'; | |||||||||||||||||||||||||||
| 135 | 77 | eval { require $mod; }; | |||||||||||||||||||||||||||
| 136 | 77 | ▶ | exists $Encoding{$name} and return $Encoding{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | 363 | return; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | # HACK: These two functions must be defined in Encode and because of | ||||||||||||||||||||||||||||
| 143 | # cyclic dependency between Encode and Encode::Alias, Exporter does not work | ||||||||||||||||||||||||||||
| 144 | 3935 | ▶ | sub find_alias { | ||||||||||||||||||||||||||
|
Subroutine
find_alias: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 145 | 3935 | goto &Encode::Alias::find_alias; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | 305 | ▶ | sub define_alias { | ||||||||||||||||||||||||||
|
Subroutine
define_alias: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 148 | 305 | goto &Encode::Alias::define_alias; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 62705 | ▶ | sub find_encoding($;$) { | ||||||||||||||||||||||||||
|
Subroutine
find_encoding: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 152 | 62705 | my ( $name, $skip_external ) = @_; | |||||||||||||||||||||||||||
| 153 | 62705 | return __PACKAGE__->getEncoding( $name, $skip_external ); | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 50358 | ▶ | sub find_mime_encoding($;$) { | ||||||||||||||||||||||||||
|
Subroutine
find_mime_encoding: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 157 | 50358 | my ( $mime_name, $skip_external ) = @_; | |||||||||||||||||||||||||||
| 158 | 50358 | my $name = Encode::MIME::Name::get_encode_name( $mime_name ); | |||||||||||||||||||||||||||
| 159 | 50358 | return find_encoding( $name, $skip_external ); | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | sub resolve_alias($) { | ||||||||||||||||||||||||||
|
Subroutine
resolve_alias: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 163 | 0 | my $obj = find_encoding(shift); | |||||||||||||||||||||||||||
| 164 | 0 | ▶ | defined $obj and return $obj->name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 0 | return; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | sub clone_encoding($) { | ||||||||||||||||||||||||||
|
Subroutine
clone_encoding: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 169 | 0 | my $obj = find_encoding(shift); | |||||||||||||||||||||||||||
| 170 | 0 | ▶ | ref $obj or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 0 | return Storable::dclone($obj); | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 69 | onBOOT; | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 69 | ▶ | if ($ON_EBCDIC) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | package Encode::UTF_EBCDIC; | ||||||||||||||||||||||||||||
| 178 | 69 | ▶ | use parent 'Encode::Encoding'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 179 | 0 | my $obj = bless { Name => "UTF_EBCDIC" } => "Encode::UTF_EBCDIC"; | |||||||||||||||||||||||||||
| 180 | 0 | Encode::define_encoding($obj, 'Unicode'); | |||||||||||||||||||||||||||
| 181 | 0 | ▶ | sub decode { | ||||||||||||||||||||||||||
|
Subroutine
decode: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 182 | 0 | my ( undef, $str, $chk ) = @_; | |||||||||||||||||||||||||||
| 183 | 0 | my $res = ''; | |||||||||||||||||||||||||||
| 184 | 0 | ▶ | for ( my $i = 0 ; $i < length($str) ; $i++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 0 | $res .= | |||||||||||||||||||||||||||
| 186 | chr( | ||||||||||||||||||||||||||||
| 187 | utf8::unicode_to_native( ord( substr( $str, $i, 1 ) ) ) | ||||||||||||||||||||||||||||
| 188 | ); | ||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | 0 | ▶ | $_[1] = '' if $chk; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | 0 | return $res; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | 0 | ▶ | sub encode { | ||||||||||||||||||||||||||
|
Subroutine
encode: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 194 | 0 | my ( undef, $str, $chk ) = @_; | |||||||||||||||||||||||||||
| 195 | 0 | my $res = ''; | |||||||||||||||||||||||||||
| 196 | 0 | ▶ | for ( my $i = 0 ; $i < length($str) ; $i++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 0 | $res .= | |||||||||||||||||||||||||||
| 198 | chr( | ||||||||||||||||||||||||||||
| 199 | utf8::native_to_unicode( ord( substr( $str, $i, 1 ) ) ) | ||||||||||||||||||||||||||||
| 200 | ); | ||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | 0 | ▶ | $_[1] = '' if $chk; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 0 | return $res; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | { | ||||||||||||||||||||||||||||
| 208 | # https://rt.cpan.org/Public/Bug/Display.html?id=103253 | ||||||||||||||||||||||||||||
| 209 | package Encode::XS; | ||||||||||||||||||||||||||||
| 210 | 69 | ▶ | use parent 'Encode::Encoding'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | { | ||||||||||||||||||||||||||||
| 214 | 69 | package Encode::utf8; | |||||||||||||||||||||||||||
| 215 | 69 | ▶ | use parent 'Encode::Encoding'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 216 | 69 | my %obj = ( | |||||||||||||||||||||||||||
| 217 | 'utf8' => { Name => 'utf8' }, | ||||||||||||||||||||||||||||
| 218 | 'utf-8-strict' => { Name => 'utf-8-strict', strict_utf8 => 1 } | ||||||||||||||||||||||||||||
| 219 | ); | ||||||||||||||||||||||||||||
| 220 | 69 | for ( keys %obj ) { | |||||||||||||||||||||||||||
| 221 | 138 | bless $obj{$_} => __PACKAGE__; | |||||||||||||||||||||||||||
| 222 | 138 | Encode::define_encoding( $obj{$_} => $_ ); | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | 0 | ▶ | sub cat_decode { | ||||||||||||||||||||||||||
|
Subroutine
cat_decode: not called CC=2 SCAR=13.7
| |||||||||||||||||||||||||||||
| 225 | # ($obj, $dst, $src, $pos, $trm, $chk) | ||||||||||||||||||||||||||||
| 226 | # currently ignores $chk | ||||||||||||||||||||||||||||
| 227 | 0 | my ( undef, undef, undef, $pos, $trm ) = @_; | |||||||||||||||||||||||||||
| 228 | 0 | my ( $rdst, $rsrc, $rpos ) = \@_[ 1, 2, 3 ]; | |||||||||||||||||||||||||||
| 229 | 69 | ▶ | use bytes; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 230 | 0 | ▶ | if ( ( my $npos = index( $$rsrc, $trm, $pos ) ) >= 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | 0 | $$rdst .= | |||||||||||||||||||||||||||
| 232 | substr( $$rsrc, $pos, $npos - $pos + length($trm) ); | ||||||||||||||||||||||||||||
| 233 | 0 | $$rpos = $npos + length($trm); | |||||||||||||||||||||||||||
| 234 | 0 | return 1; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | 0 | $$rdst .= substr( $$rsrc, $pos ); | |||||||||||||||||||||||||||
| 237 | 0 | $$rpos = length($$rsrc); | |||||||||||||||||||||||||||
| 238 | 0 | return ''; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 69 | 1; | |||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | __END__ | ||||||||||||||||||||||||||||