CARVIEW |
Select Language
HTTP/2 200
server: nginx
content-type: text/plain;charset=UTF-8
content-encoding: gzip
content-security-policy: default-src 'self'; connect-src 'self' *.google-analytics.com; img-src 'self' data: www.google-analytics.com www.googletagmanager.com; script-src 'self' 'unsafe-inline' www.google-analytics.com www.googletagmanager.com; style-src 'self'; report-uri /csp-reports
accept-ranges: bytes
age: 0
date: Tue, 29 Jul 2025 02:11:51 GMT
via: 1.1 varnish
x-served-by: cache-bom-vanm7210092-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753755111.127857,VS0,VE810
vary: Accept-Encoding
strict-transport-security: max-age=31557600
content-length: 3515
package Encode::Encoding;
# Base class for classes which implement encodings
use strict;
use warnings;
our $VERSION = do { my @r = ( q$Revision: 2.8 $ =~ /\d+/g ); sprintf "%d." . "%02d" x $#r, @r };
our @CARP_NOT = qw(Encode Encode::Encoder);
use Carp ();
use Encode ();
use Encode::MIME::Name;
use constant DEBUG => !!$ENV{PERL_ENCODE_DEBUG};
sub Define {
my $obj = shift;
my $canonical = shift;
$obj = bless { Name => $canonical }, $obj unless ref $obj;
# warn "$canonical => $obj\n";
Encode::define_encoding( $obj, $canonical, @_ );
}
sub name { return shift->{'Name'} }
sub mime_name {
return Encode::MIME::Name::get_mime_name(shift->name);
}
sub renew {
my $self = shift;
my $clone = bless {%$self} => ref($self);
$clone->{renewed}++; # so the caller can see it
DEBUG and warn $clone->{renewed};
return $clone;
}
sub renewed { return $_[0]->{renewed} || 0 }
*new_sequence = \&renew;
sub needs_lines { 0 }
sub perlio_ok {
return eval { require PerlIO::encoding } ? 1 : 0;
}
# (Temporary|legacy) methods
sub toUnicode { shift->decode(@_) }
sub fromUnicode { shift->encode(@_) }
#
# Needs to be overloaded or just croak
#
sub encode {
my $obj = shift;
my $class = ref($obj) ? ref($obj) : $obj;
Carp::croak( $class . "->encode() not defined!" );
}
sub decode {
my $obj = shift;
my $class = ref($obj) ? ref($obj) : $obj;
Carp::croak( $class . "->encode() not defined!" );
}
sub DESTROY { }
1;
__END__
=head1 NAME
Encode::Encoding - Encode Implementation Base Class
=head1 SYNOPSIS
package Encode::MyEncoding;
use parent qw(Encode::Encoding);
__PACKAGE__->Define(qw(myCanonical myAlias));
=head1 DESCRIPTION
As mentioned in L, encodings are (in the current
implementation at least) defined as objects. The mapping of encoding
name to object is via the C<%Encode::Encoding> hash. Though you can
directly manipulate this hash, it is strongly encouraged to use this
base class module and add encode() and decode() methods.
=head2 Methods you should implement
You are strongly encouraged to implement methods below, at least
either encode() or decode().
=over 4
=item -Eencode($string [,$check])
MUST return the octet sequence representing I<$string>.
=over 2
=item *
If I<$check> is true, it SHOULD modify I<$string> in place to remove
the converted part (i.e. the whole string unless there is an error).
If perlio_ok() is true, SHOULD becomes MUST.
=item *
If an error occurs, it SHOULD return the octet sequence for the
fragment of string that has been converted and modify $string in-place
to remove the converted part leaving it starting with the problem
fragment. If perlio_ok() is true, SHOULD becomes MUST.
=item *
If I<$check> is false then C MUST make a "best effort" to
convert the string - for example, by using a replacement character.
=back
=item -Edecode($octets [,$check])
MUST return the string that I<$octets> represents.
=over 2
=item *
If I<$check> is true, it SHOULD modify I<$octets> in place to remove
the converted part (i.e. the whole sequence unless there is an
error). If perlio_ok() is true, SHOULD becomes MUST.
=item *
If an error occurs, it SHOULD return the fragment of string that has
been converted and modify $octets in-place to remove the converted
part leaving it starting with the problem fragment. If perlio_ok() is
true, SHOULD becomes MUST.
=item *
If I<$check> is false then C should make a "best effort" to
convert the string - for example by using Unicode's "\x{FFFD}" as a
replacement character.
=back
=back
If you want your encoding to work with L pragma, you should
also implement the method below.
=over 4
=item -Ecat_decode($destination, $octets, $offset, $terminator [,$check])
MUST decode I<$octets> with I<$offset> and concatenate it to I<$destination>.
Decoding will terminate when $terminator (a string) appears in output.
I<$offset> will be modified to the last $octets position at end of decode.
Returns true if $terminator appears output, else returns false.
=back
=head2 Other methods defined in Encode::Encodings
You do not have to override methods shown below unless you have to.
=over 4
=item -Ename
Predefined As:
sub name { return shift->{'Name'} }
MUST return the string representing the canonical name of the encoding.
=item -Emime_name
Predefined As:
sub mime_name{
return Encode::MIME::Name::get_mime_name(shift->name);
}
MUST return the string representing the IANA charset name of the encoding.
=item -Erenew
Predefined As:
sub renew {
my $self = shift;
my $clone = bless { %$self } => ref($self);
$clone->{renewed}++;
return $clone;
}
This method reconstructs the encoding object if necessary. If you need
to store the state during encoding, this is where you clone your object.
PerlIO ALWAYS calls this method to make sure it has its own private
encoding object.
=item -Erenewed
Predefined As:
sub renewed { $_[0]->{renewed} || 0 }
Tells whether the object is renewed (and how many times). Some
modules emit C